Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML image bottom alignment inside DIV container

I have a div tag with a fixed height. Most of the images have the same height and width.

I want to align the images at the bottom of the div so that they are nicely arranged. Here is what I have so far:

<div id="randomContainer">     <div id="imageContainer">         <img src="1.png" alt=""/>         <img src="2.png" alt=""/>         <img src="3.png" alt=""/>         <img src="4.png" alt=""/>     </div>     <div id="navigationContainer">         <!-- navigation stuff -->     </div> </div> 

The CSS looks like:

div#imageContainer {     height: 160px;       vertical-align: bottom;     display: table-cell; } 

I managed to align the images at the bottom with display: table-cell and the vertical-align: bottom css attributes.

Is there a cleaner way as displaying the div as table-cell and aligning the images at the bottom of the DIV tag?

like image 715
Patric Avatar asked Jun 29 '11 12:06

Patric


People also ask

How do you position an image at the bottom of a div?

You want an image to stay at the bottom of the div right? The image has to be position:absolute; in order to use bottom:0; and left:0; AND the div it's in has to be position:relative.

How do I align something inside a div?

You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.

How do you align images in containers?

Step 1: Wrap the image in a div element. Step 2: Set the display property to "flex," which tells the browser that the div is the parent container and the image is a flex item. Step 3: Set the justify-content property to "center." Step 4: Set the width of the image to a fixed length value.


1 Answers

Set the parent div as position:relative and the inner element to position:absolute; bottom:0

like image 79
sekmo Avatar answered Sep 19 '22 13:09

sekmo