Forum Moderators: not2easy

Message Too Old, No Replies

How to aligned side by side image to bottom of div

4 images side by side aligned to bottom of div

         

ErgoWeSurrender

10:41 am on Jul 31, 2010 (gmt 0)

10+ Year Member



Okay I have 4 images all same width, but all have different heights (my images all increase in height, but it does not matter for this example). I have the following CSS:


.box {
float: left;
width: 670px;
height: 210px;
padding: 5px 0px;
margin: 0px;
text-align: center;
vertical-align: bottom;
line-height: 10px;
border: 1px solid red;
position: relative;
}
.pic {
border: 1px solid blue;
position: relative;
bottom: 0;
float: left;
}
<div class="box">
<a <img alt="img01" src="img01.png" class="pic" /></a>
<a <img alt="img02" src="img02.png" class="pic" /></a>
<a <img alt="img03" src="img03.png" class="pic" /></a>
<a <img alt="img04" src="img04.png" class="pic" /></a>
</div>


So I end up with 4 images side by side, but aligned to top of div. Instead I want to align bottom of all images to bottom of div, but still have them flow to the right.

If make change to code as follows:

.pic {
border: 1px solid blue;
position: absolute;
bottom: 0;
float: left;
}


It doesn't work as now all images line up at bottom of div, but all are on top of each other (I assume float is ignored because of absolute position?).

I've searched through many posts, and they all seem to suggest using absolute positioning- while this works for one image, it does not allow side-by-side flow of images at bottom. I'm going to use tables as a last resort, but surely this can be done in CSS?

If someone can help please, what is the correct code needed to to align bottom of more than one image to bottom of div, but still have them flow to the right?

rainborick

6:43 pm on Jul 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You're correct that you can't float an object set to position:absolute. If you set .box to "position:absolute; bottom:0;" - without any float - then your images will appear at the bottom of whatever the parent *positioned* containing element of .box happens to be. But you must explicitly position the parent containing element, even if its position is set to relative, in order for .box to be positioned where you want it to be. And, just in case, be sure you're using a complete <!DOCTYPE> statement on your document to put browsers in Standards Compliance Mode.