Discover two unique CSS 3 measurement units known as:
Understanding Viewport-Percentage Lengths
According to the W3 Candidate Recommendation linked above:
The viewport-percentage lengths are relative to the size of the initial containing block. These measurements adjust accordingly when the initial containing block's height or width changes.
The units include vh
(viewport height), vw
(viewport width), vmin
(viewport minimum length), and vmax
(viewport maximum length).
Utilizing this for Full Browser Height Dividers
To achieve a divider that fills the browser height can be done using vh
: Where 1vh
equals 1% of the viewport's height. Thus, 100vh
represents the full height of the browser window, irrespective of the element's position in the DOM tree:
HTML
<div></div>
CSS
div {
height: 100vh;
}
This simple implementation accomplishes the desired result. See a JSFiddle demo here.
Browser Support for these Innovative Units
Most major modern browsers currently support these units except Opera Mini. For more information on browser support, visit Can I use....
Implementing with Multiple Columns
In the scenario of a layout featuring left and right dividers, see a relevant JSFiddle example demonstrating a two-column layout utilizing both vh
and vw
.
Distinguishing between 100vh
and 100%
Consider this layout setup:
<body style="height: 100%">
<div style="height: 200px">
<p style="height: 100%; display: block;">Hello, world!</p>
</div>
</body>
When setting the p
tag to 100% height within a container with 200 pixels height, it equates to 200 pixels, not 100% of the body height. Contrastingly, using 100vh
makes the p
tag 100% height of the body regardless of the container height. To better visualize this difference, refer to this comparative JSFiddle example.