CSS Layout How to - Aligning multiple divs to bottom of parent div








Question

We would like to know how to aligning multiple divs to bottom of parent div.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#container {<!--from  w  w w  .  ja  v a2s.c om-->
  height: 300px;
  border: 1px solid;
  padding: 5px;
  
  display: table-cell;
    vertical-align: bottom;
}

.message {
  border: 1px solid;
  margin-top: 5px;
}
</style>
</head>
<body>
  <p>Top of page</p>
  <div id="container">
    <div class="message">Message 4</div>
    <div class="message">Message 3</div>
    <div class="message">Message 2</div>
    <div class="message">Message 1</div>
  </div>
  <p>Bottom of page</p>
</body>
</html>

The code above is rendered as follows: