views:

1339

answers:

3
+1  Q: 

IE6 float <img>

Sometimes in a floated div. IE6 does not display tags, however it does space the image correctly, and when you right click the image it gives correct details like size and file size. It just does not display the image:

<div style="float:left">
    <img src="one.gif" />
</div>
<div style="float:left">
    <img src="two.gif" />
</div>

These images are not displayed in IE6 but are displayed in Firefox/Safari/etc... What is the workaround?

+1  A: 

One workaround is to use:

position: relative;
float: left;
Robert
This may cause other issues. Test it or see my answer about hasLayout below
Chris Lively
+5  A: 

It's called the "Peekaboo" bug. For more information see:

http://www.positioniseverything.net/explorer/peekaboo.html

The preferred method to fix this is to set the hasLayout property on the container to true

Chris Lively
The fix we use most often (very selectively) is to set zoom:1. This can also have some bad side effects if used too liberally. Setting hasLayout directly requires JavaScript to be enabled...
Rex M
I believe they were saying to inline it like the other styles. For example: <div style='hasLayout:true;float:left'>
Chris Lively
The method I've used for triggering hasLayout is to give the element a height of 1%
Bayard Randel
A: 

Try also floating the images, that will work!

div img {
   float:left;
}

By default images are display:inline; when they are in a floated div the div won't surround them. I believe this is the cause of the display bug.

Matthew James Taylor