views:

270

answers:

4

I've been banging my ahead on this IE7 bug for the last few days and it's time to resort to the mind of the crowd.

I have the following HTML and CSS: http://beerpla.net/for_www/ie7_test/test.html

The goal is to have a <ul>, with each <li> containing a small icon and some text. Multiline text would be aligned to itself and not wrap under the image.

I've tried using float:left on the image and a bunch of other things, and finally I thought the position:absolute would work for sure but in IE7 I consistently see the text pop off to the next line and get misaligned with the image:

alt text

This is what I expect it to look like:

alt text

I even tried to make the div display:inline which kind of worked but then started wrapping under the image for long lines, so it was no good. zoom:1 also produced a similar effect.

I'm at a loss at the moment. This code works fine in all other browsers. IE7 is a special, very special child.

Any ideas?

Thank you.

Edit: If you have IE8, you can emulate IE7 by pressing F12 and then Alt-7.

+1  A: 

Try using padding on the li instead of margin on the div. If display:inline worked, it's probably IE choking on working out the div's box model in some arcane way: padding on the li and maybe display:inline on the div may iron it out.

D_N
That did it! I haven't seen a more ridiculous behavior from a browser in a while. I'd still like some explanation on why it doesn't work the other ways, especially position:absolute though, and maybe get a cleaner solution.
Artem Russakovskii
A: 

Moving the <img> tag into the <div> fixes the issue. Still unknown to me why IE7 does what it does.

Artem Russakovskii
+2  A: 

instead of putting the image as an element, try using background property. like so

ul li { background url(path to image) 0 0 no-repeat; padding: 0 0 0 20px; }

note: you might have to adjust the padding to suit the distance you want to maintain between the image and text.

pixeltocode
+1  A: 

Go back to floating your image left, and then add overflow: hidden; to the div. The text will no longer wrap below the image, and there are no side-effects unless you are trying to position content from inside the div out (don't see that here). Completely compatible cross-browser. With IE6 you simply need to add hasLayout by any means to get the same effect.

Eric Meyer