Internet Explorer box model bug

From Wikipedia, the free encyclopedia

The above image demonstrates differences between the content (red) and border (blue) box models.
The above image demonstrates differences between the content (red) and border (blue) box models.

The Internet Explorer box model bug is one of the best-known software bugs in a popular implementation of Cascading Style Sheets (CSS). It affects CSS-aware versions of Microsoft’s Internet Explorer Web browser for Windows up to version six. Internet Explorer 6 and newer are not affected in their standards-compliant mode; they are affected only in “quirks mode”. The bug did not affect Internet Explorer for Mac, on the Apple Macintosh platform although development for it ended in 2003.

Contents

[edit] Bug

The CSS box model describes how certain elements of Web pages are displayed by graphical browsers. The box model allows block-level elements—such as p and blockquote—to be surrounded by padding, borders, and margins. According to the CSS1 specification, released by the World Wide Web Consortium (W3C) in 1996 and revised in 1999, when a width or height is explicitly specified for any block-level element, it should determine only the width or height of the content within the box, with the padding, borders, and margins applied afterward. [1][2] Internet Explorer 5 incorrectly includes the padding and borders within a specified width or height; this results in a narrower or shorter rendering of a box.[3]

[edit] Workarounds

Internet Explorer versions 6 and 7 are not affected by the bug if the page contains certain HTML document type declarations. These versions maintain the buggy behavior when in quirks mode for reasons of backward compatibility.[4] For example, quirks mode is triggered:

  • When the document type declaration is absent or incomplete;
  • When an HTML 3 or earlier document is encountered;
  • When an HTML 4.0 Transitional or Frameset document type declaration is used and a system identifier (URI) is not present;
  • When an SGML comment or other unrecognized content appears before the document type declaration, or if there are errors elsewhere in the document;
  • Internet Explorer 6 also uses quirks mode if there is an XML declaration prior to the document type declaration.[5]

Various workarounds have been devised to force Internet Explorer versions 5 and earlier to display Web pages correctly. These workarounds generally exploit unrelated bugs in Internet Explorer’s CSS selector processing in order to hide certain rules from the browser. The best known of these workarounds is the “box model hack” developed by Tantek Çelik. Çelik developed this idea during his time at Microsoft while working on Internet Explorer for the Macintosh, which is not affected by the bug. It involves specifying a width declaration for Internet Explorer for Windows, and then overriding it with another width declaration for CSS-compliant browsers. This second declaration is hidden from Internet Explorer for Windows by exploiting other bugs in the way that that browser parses CSS rules. The implementation of these CSS “hacks” has been further complicated by the public release of Internet Explorer 7, which has had some issues fixed, but not others.[4]

Box model hacks have proven unreliable because they rely on bugs in browsers’ CSS support that may be fixed in later versions. For this reason, some Web developers have instead recommended either avoiding specifying both width and padding for the same element or using conditional comment and/or CSS filter to work around the box model bug in older versions of Internet Explorer.[6][7]

[edit] Support for Internet Explorer's box model

Web design professionals Douglas Bowman and Ethan Marcotte have stated that the original Internet Explorer box model actually represents a better, more logical approach based on common sense.[8][9] An example given by Peter-Paul Koch is a physical, real-world box, whose dimensions always refer to the box itself, including potential padding, but never its content.[10] In CSS designs, this definition allows the exact application of both relative dimensions and absolute padding to any given box, which is not possible with the W3C model without workarounds.[11] Peter-Paul Koch also says that this box model is more useful for graphic designers, who create designs based on the visible width of boxes rather than the supposed width of their content.[12] Another argument, given by Bernie Zimmermann in support of the Internet Explorer box model, is its closeness to the definition of cell dimensions and padding in the HTML table model, as defined by the W3C and implemented in most browsers.[13]

In some early CSS3 Box Model Specification and Basic User Interface Module drafts, the W3C considered an explicit choice of box models via proposed box-width and box-height properties. These are not included in the current CSS3 draft.

[edit] References

  1. ^ Håkon Wium Lie; Bert Bos (December 17, 1996). Cascading Style Sheets, level 1. W3C. Retrieved on 2006-12-09.
  2. ^ Håkon Wium Lie; Bert Bos (January 11, 1999). Cascading Style Sheets, level 1. W3C. Retrieved on 2007-06-24.
  3. ^ Lance Silver (March 2001). CSS Enhancements in Internet Explorer 6. MSDN Library. Microsoft. Retrieved on 2007-06-24.
  4. ^ a b Markus Mielke (2006-09-26). Cascading Style Sheet Compatibility in Internet Explorer 7. MSDN. Retrieved on 2007-06-24. "Pages authored under non-strict mode (quirks) will not change behavior in IE7 and will not be affected by broken CSS filters.Pages authored under non-strict mode (or “quirks mode”) will not change behavior in IE7."
  5. ^ !DOCTYPE. Retrieved on 2007-01-13. "The following examples show how to use the !DOCTYPE declaration to specify the DTD a document conforms to, and to switch Internet Explorer 6 and later to standards-compliant mode."
  6. ^ Roger Johansson (2006-12-21). Internet Explorer and the CSS box model. 456 Berea Street. Retrieved on 2007-01-14.
  7. ^ Arve Bersvendsen (February 2004). Hack-free CSS for IE. Arve Bersvendsen's weblog. Retrieved on 2007-01-16.
  8. ^ Vorsprung durch Webstandards | Douglas Bowman declares his love to CSS …
  9. ^ Vorsprung durch Webstandards | Ethan Marcotte declares his love to CSS …
  10. ^ CSS2 - Box model tweaking
  11. ^ CSS Box Model
  12. ^ Vorsprung durch Webstandards | Peter-Paul Koch declares his love to CSS …
  13. ^ Box Model Enlightenment, Bernie Zimmermann

[edit] External links


Languages