Rounding errors with em units

There appear to be rounding errors in many browsers, particularly IE7, when specifying width in em units.

Take the following as an example: two small divs nested inside a larger one. The outer div has a width of 18em. Each inner div has a width of 7em and margins of 1em. Since horizontal margins do not collapse, this layout should fit perfectly flush: (2 * 7em) + (4 * 1em) = 18em.

width: 18em
width: 7em
margin: 1em

In certain browsers, at certain font-sizes, the layout breaks: the second inner box falls onto the next line, as if there were not enough space to accommodate it. I’m guessing this is a rounding error of some description.

font-size: 90%
font-size: 80%

In this example, at least in my environment, an IE7 rounding error causes the second float to ‘drop’ below the first.

font-size: 70%

Comments

Leave a comment