CSS Layout How to - Stretch panels in a fixed height parent block








Question

We would like to know how to stretch panels in a fixed height parent block.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.A {<!--  w w  w .  j  ava  2  s .  c o m-->
  width: 100%;
}

.parent {
  height: 300px;
  width: 300px;
  position: relative;
}

.a1 {
  height: 100px;
  background-color: pink;
}

.a2 {
  height: 100px;
  background-color: beige;
}

.a3 {
  background-color: yellow;
  position: absolute;
  top: 200px;
  bottom: 0;
}
</style>
</head>
<body>
  <div class="A parent">
    <div class="A a1">a1</div>
    <div class="A a2">a2</div>
    <div class="A a3">a3</div>
  </div>
</body>
</html>

The code above is rendered as follows: