Home Web Front-end CSS Tutorial Tips for adjusting row height based on screen size using CSS Viewport units vmin and vmax

Tips for adjusting row height based on screen size using CSS Viewport units vmin and vmax

Sep 13, 2023 am 09:52 AM
Yukidaka Adjustment css viewport vmin vmax

使用 CSS Viewport 单位 vmin 和 vmax 来实现根据屏幕尺寸调整行高的技巧

Use CSS Viewport units vmin and vmax to realize the technique of adjusting row height according to the screen size

Nowadays, the penetration rate of mobile devices is getting higher and higher. In order to improve User experience, web design requires a good responsive layout. When doing responsive design, a problem often encountered is how to adjust the row height according to the screen size. Fortunately, the CSS Viewport units vmin and vmax can help us achieve this goal.

The vmin and vmax units respectively specify a set of length units calculated relative to the viewport width or height. vmin specifies a length value that is the smaller of the viewport width and height. vmax specifies a length value that refers to the larger of the viewport width and height.

Suppose we have a page that contains multiple lines of text. We want the text line height to automatically adapt when the viewport width or height changes. Below are the implementation steps and corresponding code examples.

First, we need to set a base value. When the width or height of the viewport is 100vmin, the row height is set to 1vmin. In this way, when the width or height of the viewport is less than or equal to 100vmin, we can ensure that the row height will not exceed the width or height of the viewport.

html, body {
height: 100%;
margin: 0;
padding: 0;
}

.container {
height: 100vh; / Set the container height to the viewport height/
}

.text {
font-size: 1.5rem;
line-height: 1vmin; / Set the line height to 1vmin /
}

Next, we can contain multiple lines of text in a container and set the height of the container to the viewport height, so that the text This will completely fill the container. At the same time, we also set the font size of the text to 1.5rem to ensure the readability of the text.


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tempus vestibulum diam, quis commodo ipsum sagittis eu.


Nulla laoreet mollis nisi, id interdum mi commodo quis. Sed semper magna id vehicula pellentesque.


Nunc ex nibh, feugiat at felis quis, ullamcorper vestibulum elit. Nam vitae turpis et dui accumsan faucibus.


With the above code, we have Completed the operation of adjusting the row height according to the screen size. Under different viewport sizes, the line height of the text will be scaled accordingly according to the current viewport size.

It should be noted that since vmin and vmax are calculated relative to the viewport size, caution should be used when using these units to avoid excessively enlarging or shrinking elements. In addition, different browsers may have some differences in how they calculate the viewport size, so the actual use may be slightly different.

To summarize, using the CSS Viewport units vmin and vmax provides convenience in adjusting row heights according to the screen size. By dynamically adjusting row heights, we can achieve a more flexible and adaptable responsive design. This technique can improve the user experience on various mobile devices and allow our web pages to better adapt to different screen sizes.

The above is the detailed content of Tips for adjusting row height based on screen size using CSS Viewport units vmin and vmax. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem of missing 1920x1080 resolution in Win10 How to solve the problem of missing 1920x1080 resolution in Win10 Jan 06, 2024 am 09:08 AM

The win10 system is a very excellent system, and its strong stability is the most powerful part of the system. Today, the editor brings you a solution to the problem that the win10 resolution does not have 1920x1080! Let's take a look together if necessary. Solution to the problem that the resolution of win10 system is not 1920x1080: Note: The problem that the resolution of win10 is not 1920x1080 is caused by the graphics card driver! So I just need to update the graphics card driver. (The specific steps are as follows) 1. Right-click the computer and select Manage to open. 2. Find the device manager from the left side of the opened management interface. 3. Continue to find the display adapter from the left side in the opened device manager interface and open it. 4. Finally, right-click and select

How to adjust screen brightness on Windows 11 How to adjust screen brightness on Windows 11 Jan 02, 2024 pm 03:17 PM

In win11, if the screen brightness is too dark, you will not be able to see the picture clearly, and if it is too bright, it will dazzle your eyes. So how do you adjust the screen brightness in win11? In fact, you can adjust it in the display settings, which is very convenient. How to adjust the screen brightness in win11: 1. First open the "Start Menu" below 2. Then click "Settings" above 3. After opening, enter the "Display" settings on the right. 4. After opening, slide the brightness slider to adjust the screen brightness.

How to modify table row height in vue How to modify table row height in vue Jan 31, 2023 pm 04:11 PM

How to modify table row height in vue: 1. Open the corresponding vue file; 2. View the table style code; 3. Modify ":row-style="{height:'20px'}" :cell-style="{padding :'0px'}""The table row height can be modified by the attribute value.

How to change web page zoom ratio in Edge browser How to change web page zoom ratio in Edge browser Jan 29, 2024 pm 09:06 PM

How to adjust the web page display ratio of the Edge browser? When we use the edge browser, if we want to adjust the web page display ratio, how should we adjust it? Let’s introduce it below! When we use the edge browser to browse the web, the text on some web pages is relatively small. In this case, we can adjust the web page proportion to enlarge the entire page so that we can clearly see the text. So what is the specific operation? Let me introduce it below! If not, let’s read on! Tips for adjusting the display ratio of Edge browser web pages: 1. After using Edge browser to open the web page that needs to be enlarged, click the "Settings and Others" icon consisting of three dots in the upper right corner of the browser. 2. Then find the “Zoom” option in the Edge browser menu window that pops up below.

How to adjust mouse dpi in win11 How to adjust mouse dpi in win11 Dec 29, 2023 pm 04:34 PM

For gamers, mouse dpi is very important and affects the operating feel. So how to adjust mouse dpi in win11? In fact, the adjustment method may be different depending on the mouse model we use. How to adjust mouse dpi in win11 Method 1: (General) 1. First, open the "Settings" application and click on "Bluetooth and other devices" on the left. 2. Then click to enter the "Mouse" setting option on the right. 3. Finally, click on this page to modify the mouse speed dpi. Method 2: (Professional equipment) 1. Professional mice usually come with a dpi adjustment button. 2. If not, download a professional driver software and adjust the dpi in it.

How to edit photos on iPhone using iOS 17 How to edit photos on iPhone using iOS 17 Nov 30, 2023 pm 11:39 PM

Mobile photography has fundamentally changed the way we capture and share life’s moments. The advent of smartphones, especially the iPhone, played a key role in this shift. Known for its advanced camera technology and user-friendly editing features, iPhone has become the first choice for amateur and experienced photographers alike. The launch of iOS 17 marks an important milestone in this journey. Apple's latest update brings an enhanced set of photo editing features, giving users a more powerful toolkit to turn their everyday snapshots into visually engaging and artistically rich images. This technological development not only simplifies the photography process but also opens up new avenues for creative expression, allowing users to effortlessly inject a professional touch into their photos

How to adjust the subtitles of National K-song How to adjust the subtitles of National K-song Feb 23, 2024 pm 07:16 PM

How to adjust the subtitles of karaoke? The subtitles of lyrics can be adjusted in the National Karaoke APP, but many users do not know how to adjust the subtitles of Karaoke moments. The latest solutions to the problems will be continuously sorted out below. Next is the National Karaoke that the editor brings to users. Here is a graphic tutorial on how to adjust subtitles. Interested users can take a look together! Tutorial on the use of National Karaoke. How to adjust the subtitles of National Karaoke. 1. First open the Universal Karaoke APP, switch to the [Voice Sing] section on the main page, select your favorite song and click [K Song]; 2. Then switch to the Karaoke page, Click the red button [Start Singing] at the bottom; 3. Then on the latest page, click the [three dots] function in the upper right corner; 4. Finally, expand the function bar at the bottom and select [Font Size] to adjust

How to adjust Win11 mouse DPI? How to adjust Win11 mouse DPI? Jun 30, 2023 pm 12:53 PM

How to adjust mouse dpi in Win11? The mouse is an essential device for using a computer. For some players who like to play games, the higher the DPI value of the mouse, the higher the sensitivity. However, some friends using the Win11 system want to modify the DPI value but do not know. How to operate, let’s take a look at how to modify the mouse dpi value in Win11 system with the editor. Detailed steps for adjusting mouse dpi in Win11 1. First, let’s talk about a general method, open the system settings. 2. After opening it, enter Bluetooth and other devices on the left. 3. Then enter the mouse settings on the right. 4. Finally, you can modify the mouse speed dpi. The above is [How to adjust mouse dpi in Win11-Win11 adjustment

See all articles