css get viewport height code example

Example 1: what if i want a section to take the height of a viewport html

/* in css file */

html,
body {
  height: 100%;
  margin: 0;
}
section {
  height: 100vh;
}
section:nth-child(1) {
  background: lightblue;
}
section:nth-child(2) {
  background: lightgreen;
}
section:nth-child(3) {
  background: purple;
}
section:nth-child(4) {
  background: red;
}
section:nth-child(5) {
  background: yellow;
}

Example 2: vh in css

/*
vh	Relative to 1% of the height of the viewport*
*/
<!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>

/*
I hope it will help you.
Namaste
Stay Home Stay Safe
*/

Example 3: what are the viewport based units in html

The viewport based units are:
vh , vw , vmin, vmax .

Example 4: what if i want a section to take the height of a viewport html

<!--in html file-->
<section></section>
<section></section>
<section></section>
<section></section>
<section></section>

Tags:

Css Example