Diagnosis
- Affected browsers:
- Internet Explorer 5.5 and 6 on Windows.
- Visual appearance:
- shifted/disappeared background (possibly content as well).
- Triggers:
- position: static (the default) and hasLayout set to false.
What a stupid bug! You set background on the element but for some reason it is not there in IE. The following demo also shows that the inner div's background disappeared. Ah, IE, the browser of the future!
HTML:
<div id="demoContainer">
<div id="demoInside">Stupid IE</div>
</div>
CSS:
div#demoContainer
{
background: #00d;
}
div#demoInside
{
background: #0f0;
}
When this demo is viewed in Internet Explorer version below 7 the green background on the div#demoInside is not visible.
The fix for this bug is quite clean and simple, we do not even need to put in the IE conditional comments. All we need to do is set position: relative; to both elements. Here is the fixed code for the demo above:
div#demoContainer
{
position: relative;
background: #00d;
}
div#demoInside
{
position: relative;
background: #0f0;
}
However, this might not fix the issue of shifted or disappered content.
Another fix for this problem would be to set hasLayout to true on the container, in that case we don't need to set position: relative; on either of the elements. Here what the alternative fix would look like
<!--[if lt IE 7]>
<style type="text/css">
div#demoContainer
{
zoom: 1;
}
</style>
<![endif]-->
That is all! Happy fixing =)
This page was written by Zoffix Znet. It may be copied, modified, and distributed freely as long as it attributes the original author and maintains the original license. See the license for details. This work is copyright © 2006 Zoffix Znet and is licensed under a Creative Commons Attribution Share-Alike License.