Vertical alignment of an image in a block with a fixed height
I am 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 is not surprising, but I really need to fix it if possible.
Edited to add: Cannot use tables or background image.
Many thanks
+1
source to share
4 answers
As much as it pains me to say this and at the risk of being drawn and quartered by the purists 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>
0
source to share