CSS Layout How to - Force a DIV block to extend to the bottom of a page even if it has no content








Question

We would like to know how to force a DIV block to extend to the bottom of a page even if it has no content.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
html, body {<!--from ww  w  .j ava 2 s .c o m-->
  height: 100%;
  display: flex;
  flex-direction: column;
}

body>* {
  flex-shrink: 0;
}

.div1 {
  background-color: #EEE;
}

.div2 {
  background-color: #DDD;
}

.div3 {
  background-color: #CCC;
  flex-grow: 1;
}
</style>
</head>
<body>
  <div class=div1>
    div1<br> div1<br> div1<br>
  </div>
  <div class=div2>
    div2<br> div2<br> div2<br>
  </div>
  <div class=div3>
    div3<br> div3<br> div3<br>
  </div>
</body>
</html>

The code above is rendered as follows: