CSS Layout How to - Take all available height inside parent without overflowing








Question

We would like to know how to take all available height inside parent without overflowing.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#wr {<!--from  w  w  w . j a v  a 2  s  .c o  m-->
  height: 400px;
  width: 100%;
  margin: 50px auto;
  border: 1px solid black;
  position: relative;
}

#con_top {
  height: 40px;
  margin: 5px;
  border: 1px solid red;
  background:#EEE;
}

#con_bottom {
  background:#AAA;
  border: 1px solid blue;
  margin: 5px;
  position: absolute;
  top: 45px;
  bottom: 0;
  left: 0;
  right: 0;
}
</style>
</head>
<body>
  <div id="wr">
    <div id="con_top"></div>
    <div id="con_bottom"></div>
  </div>
</body>
</html>

The code above is rendered as follows: