html - Align child to top of inline parent in Internet Explorer -
i want align element top of enclosing inline element. therefore i'm using code:
html:
<span id="outer"> <img src="http://placekitten.com/200/200" /> <span id="inner">watch me align!</span> </span>
css:
#outer { position: relative; } #inner { position: absolute; top: 0; left: 0; background-color: white; } img { vertical-align: top; }
this code works in firefox , chrome: text positioned in top-left corner of image. in internet explorer text sticks bottom of image.
you can see in my fiddle.
after reading this msdn entry conclude vertical-align property doesn't apply on inline elements since don't support valign attribute.
my best idea reposition text using javascript, may agree: that's no elegant solution.
so, know neat trick make work in internet explorer?
important! following css properties of parent can't changed:
#outer { display: inline; position: relative; float: none; }
this should work: http://jsfiddle.net/gcg4d/
html
<span id="outer"> <img src="http://placekitten.com/200/200" /> <span id="inner">watch me align!</span> </span>
css
#outer { position: relative; display:inline-block; width:auto; } #inner { position: absolute; top: 0; left: 0; background-color: white; display:block; } img { display:inline-block; }
Comments
Post a Comment