Solution (Clean Solution)
Date of the Solution
Tue Aug 18 12:28:06 2009
Fixed Versions
All of the affected
Description
While proposing the fix in this solution, I will assume that due to "Expanding Width Bug" in IE6, the solution will not cause any side effects. If you are not supporting IE6, the bug is easily fixed in IE7 by giving our <p> "layout". Let's the the demo for fixing the bug in both IE6 and IE7:
Fixed demo is available on a separate page
- HTML Code:
<div>
<p>
<span>A</span>
<span>B</span>
<span>C</span>
<span>D</span>
</p>
</div>
- CSS Code:
div {
width: 100px;
}
p {
margin: 0 1px 0 0;
width: 125px;
}
span {
border: 1px solid #000;
float: left;
width: 120px;
}
What I did here is added width to our <p> (the container of floats) with the value that is larger than that of the floats. The width needed to contain the bug needs to be a "magic number" larger than the overal width of floated elements (that is their width plus padding and border if any of those are set). This magic number seems to be 3px. We have 120px width floats and 1px surrounding border set on them; this gives us 122px, add the magic number and we get 125px - solves the bug in both, although in IE7 the fix may be not related to the value of width but is fixed by "layout" that width gives.