Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning multiple divs to bottom of parent div

Tags:

html

css

styles

I have multiple child divs within a parent div. Using CSS, is it possible to vertically align all of the child divs to the bottom of the parent container so that something like the following would be displayed:

enter image description here

The height of the child divs will be unknown (dynamic).

<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>

style below:

#container {

    height: 500px;

    }

Problem demo.

like image 201
Stack Man Avatar asked Jan 22 '13 03:01

Stack Man


People also ask

How do I align the content at the bottom of a div?

To align the div content to the bottom, use position: relative to the container class and position: absolute to the div element.

How do I center child divs in parent div?

Like last time, you must know the width and height of the element you want to center. Set the position property of the parent element to relative . Then set the child's position property to absolute , top to 50% , and left to 50% . This just centers the top left corner of the child element vertically and horizontally.

How do I position a div under one another?

If you want the two div s to be displayed one above the other, the simplest answer is to remove the float: left; from the css declaration, as this causes them to collapse to the size of their contents (or the css defined size), and, well float up against each other.


1 Answers

You can use the following styles for the container

display: table-cell;
vertical-align: bottom;

Solution demo here.

like image 185
Arun P Johny Avatar answered Oct 19 '22 11:10

Arun P Johny