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?
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.
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.
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.
Set the parent div as position:relative
and the inner element to position:absolute; bottom:0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With