
A simple way to stretch a block to the full height of the screen, or CSS3 Viewport Units

In this article, I will introduce you to the vw, vh, vmin, and vmax units that appeared in CSS3.
What is Viewport Units?
Viewport Units are relative units of measure calculated as a percentage of the size of the browser viewing area. These units appeared in the third version of the CSS specification .
Units of measure vh and vw
vh
and vw
you can decode how viewport height and viewport width are the height and width of the viewport, respectively. 1vh
equal to one percent of the height of the viewport, 1vw
equal to one percent of the width of the viewport.Units of measurement vmin and vmax
vmin
and vmax
stands for viewport minimal and viewport maximal . 1vmin
compares the values 1vh
and 1vw
choosing the smaller of them. 1vmax
does the same, but selects the larger of the two values. In other words, if the smartphone has a screen width less than the height, it vmin
will be calculated relative to the width, and vmax
will be calculated relative to the height of the screen.Usage example
Now the use of full-screen sections is trending. Especially often they are used in landing pages. There are many ways to make such a section, but the easiest and most elegant way is to use a unit of measure
vh
.section {
height: 100vh; /* высота секции равна высоте области просмотра */
}
Check out the demo .
Browser support
Quite a lot of browsers support these units of measurement, which is good news. There are no problems with the latest versions of Chrome, Safari, Opera, and Firefox. IE since the ninth version has partial support. The problem with mobile browsers: Opera Mini does not support these units at all, Android Browser supports them only from version 4.4. View detailed statistics .