relative units css code example
Example 1: vh and vw
div
{
display: inline-block;
height: 100vh;
width: 100vw
}
Example 2: css em
em -> Relative to the font-size of the element
(2em means 2 times the size of the current font)
Example 3: vh in css
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
font-size: 20vh;
}
</style>
</head>
<body>
<h1>Hello</h1>
<p>Resize the height of the browser window to see how the font-size of h1 changes.</p>
<p>1vh = 1% of viewport height.</p>
<p>The vh unit is not supported in IE8 and earlier.</p>
</body>
</html>
Example 4: em css
Example 5: pixels and em mdn
html {
font-size: 62.5%;
}
span {
font-size: 1.6em;
}
Example 6: what are the viewport based units in html
The viewport based units are:
vh , vw , vmin, vmax .