CSS Layout How to - Use absolute position to set div with 100% height of window








Question

We would like to know how to use absolute position to set div with 100% height of window.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!--  w ww  .  j a  v  a 2  s.c  om-->
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: red;
}
</style>
</head>
<body>
  <div>
    <p>Hello</p>
  </div>
</body>
</html>

The code above is rendered as follows: