CSS Layout How to - Position absolute for stretching panels








Question

We would like to know how to position absolute for stretching panels.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
html, body {<!--from www . ja v a 2s  . c om-->
  height: 100%;
  margin: 0;
}

body {
  background-color: #E3E3E3;
}

#pageWrapper {
  margin: 0 auto;
  position: relative;
  width: 600px;
  height: 100%;
}

header {
  display: block;
  width: 100%;
  height: 100px;
  background: yellow;
}

#contentWrapper {
  width: 100%;
  position: absolute;
  top: 100px;
  bottom: 100px;
  left: 0;
  background: blue;
}

#navWrapper {
  width: 100%;
  position: absolute;
  height: 100px;
  bottom: 0px;
  left: 0;
  background: green;
}
</style>
</head>
<body>
  <div id="pageWrapper">
    <header> Header </header>
    <div id="contentWrapper">Content</div>
    <div id="navWrapper">Nav</div>
  </div>
</body>
</html>

The code above is rendered as follows: