views:

227

answers:

4

I'm trying to BOTTOM align an image in a fixed-height block:

div { float: left; width: 100px; height: 100px; line-height: 100px; }
div img { vertical-align: middle; }

...works in modern browsers, except IE! IE sucks no wonder, but I really need a fix, if possible.

Edited to add: Can't use tables or background image.

Many thanks

A: 

As much as it pains me to say it and at the risk of being drawn and quartered by the purists out there, the most reliable way to vertically align something in a universally compatible way is to use a table.

table {
    float: left; 
    width: 100px; 
    height: 100px; 
    line-height: 100px;
}

<table cellspacing="0" cellpadding="0">
    <tr>
        <td align="center" valign="bottom"><img src="foo.jpg" /></td>
    </tr>
</table>
inkedmn
No thanks, I already know that method, but I can't put tables for that inside an otherwise valid xhtml strict layout.
Nimbuz
A: 

Simplest way to do this is to use in the DIV style="background:url(...) no-repeat center bottom" instead of IMG tag.

Thinker
Knew this method too, but can't use background image here.
Nimbuz
A: 

Why can't you just position:relative the division, position:absolute and mess with bottom/left properties?

Or toggle it's position to inline-block and play around.

meder
aha, I usually use this method, don't know why I didn't think of this. Thanks! :-)
Nimbuz
Ah, now the drop-down menu above hides behind those images. Z-index doesn't seem to have any effect. :-(
Nimbuz
It would help seeing an example to solve your stacking order dilemma. You probably aren't accounting for parents which have a position, though it's too hard to tell without seeing anything. Picture yourself in my position.
meder
A: 

I can´t find it right now, but I saw something positioning the element at 50% (the top) and then giving it a negative top-margin of -50%.

Just for the vertical alignment obviously...

jeroen