Do we all hate IE because the IE box model makes more sense?
For those who don’t know and are lazy to look it up, prior to IE 6, IE used to include border and padding in its calculation of the width (and height) of a page element. This is different than the “standard” W3C box model, which defines width as only the width of the content, not including padding and border.
In IE 6 and 7, you have to manually enable the W3C box model by adding a doctype. IE 8 uses the standard box model by default. This makes IE more consistent with other browsers.
However, a lot people find the old IE box model more intuitive. In fact, if you set a 100px width to an element, you want it to be 100px; nothing less, nothing more. You won’t want it to appear bigger and screw your page up when there’s padding and border.
You can actually enable the IE box model on other browsers by doing this:
/* enable good-old IE box model on all divs
** add to the selector for wider adoption
border-box means that the width (or height) is calculated border-to-border (border + padding + content width). The opposite (default) value is content-box.
Pretty cool huh?
Humm… not really. It’s only supported by IE8 (more on IE8 later), Webkit browsers (e.g. Chrome) and Mozilla browsers (e.g. Firefox). We’re missing IE6 and IE7.
Unless you don’t care about IE6 and IE7, I recommend that you don’t use border-box to switch your box model.
If you are one of the pioneers who don’t give a ____ on those bad browsers, you still need to watch out its strange behavior on IE8.
On IE8, border-box applies to width and height. It does not apply to min-width and min-height! That means if a container has a min-height, it’s going to exclude the padding and border in the calculation even if border-box is applied. The container will appear taller than expected in this case.
You can try it out on this test page: http://jsfiddle.net/XS2JF/. The one with border-box should be shorter, but they appear the same on IE8.
Conclusion: let’s not deal with box models anymore. It’s not yet 2013.