HTML Element Style How to - Strech div to fill body








Question

We would like to know how to strech div to fill body.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
html, body {<!--   w  w  w .  j a v  a  2 s .  c o  m-->
  margin: 0;
  padding: 0;
  border: 0;
}
#top, #mid, #bot {
  position: absolute;
  width: 100%
}

#top {
  height: 20px;
  background: red;
  top: 0;
}

#mid {
  background: #EEE;
  top: 20px;
  bottom: 20px
}

#bot {
  height: 20px;
  background: #AAA;
  bottom: 0
}
</style>
</head>
<body>
  <div id="top">1</div>
  <div id="mid">2</div>
  <div id="bot">3</div>
</body>
</html>

The code above is rendered as follows: