Thursday, December 1

Today’s Fun IE6 Float Bug

I’m working on a bit of CSS where I’d like a div to take up only as much space as its contents require. Normally, this is trivial to do with the float property.

Unfortunately, in IE the div was still trying to take up 100% of the available space.

The problem was that the div had a few child divs with their height property set. This erroneously caused those divs to expand their width, which expanded the parent as well.

My solution was to switch from height to font-size and line-height to get the height I wanted in the child elements. To adapt this for Firefox I needed to put a single non-breaking space in each child div.