Internet Explorer box model bug
From Wikipedia, the free encyclopedia
The Internet Explorer box model bug is a software bug in the implementation of Cascading Style Sheets in earlier versions of Microsoft’s Internet Explorer web browser for Microsoft Windows.[1][2] Internet Explorer 6 and newer are not affected in their standards-compliant mode, but for compatibility reasons, the bug is still present when a page is rendered in "quirks mode". The bug does not affect Internet Explorer for Mac, though that browser was discontinued by Microsoft in 2006.
Contents |
[edit] Background
The Cascading Style Sheets (CSS) specification describes how elements of web pages are displayed by graphical browsers. Section 4 of the CSS1 specification defines a "formatting model" that gives block-level elements—such as p
and blockquote
—a width and height, and three levels of boxes surrounding it: padding, borders, and margins.[3] While the specification never uses the term "box model" explicitly, the term has become widely used by web developers and web browser vendors.
Before HTML 4 and CSS, very few HTML elements supported both border and padding, so the definition of the width and height of an element was not very contentious. However, it varied depending on the element. The HTML width attribute of a table defined the width of the table including its border.[4] On the other hand, the HTML width attribute of an image defined the width of the image itself (inside any border).[citation needed] The only element to support padding in those early days was the table cell. Width for the cell was defined as "the suggested width for a cell content in pixels excluding the cell padding."[5]
CSS introduced margin, border and padding for many more elements. It adopted a definition width in relation to content, border, margin and padding similar to that for a table cell.[6] This has since become known as the W3C box model.
At the time, very few browser vendors implemented the W3C box model to the letter. The two major browsers at the time, Netscape 4.0 and Internet Explorer 4.0 both defined width and height as the distance from border to border.[7] This has been referred to as the traditional[8] or the Internet Explorer box model.[9]
[edit] Bug
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 visible element, with the padding, borders, and margins applied afterward. [10][3] Internet Explorer 5 includes the content, padding and borders within a specified width or height; this results in a narrower or shorter rendering of a box.[11]
[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.[12] 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
- If there are errors anywhere in the document
- Internet Explorer 6 also uses quirks mode if there is an XML declaration prior to the document type declaration.[13]
Various workarounds have been devised to force Internet Explorer versions 5 and earlier to display Web pages using the W3C box model. 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, a former Microsoft employee who developed this idea while working on Internet Explorer for the Macintosh. 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.[12]
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 filters to work around the box model bug in older versions of Internet Explorer.[14][15]
[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 in their opinions.[16][17] 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.[18] 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.[19] 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 width of their content.[20] 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.[21]
The W3C is also including a "box-sizing" property in CSS3 called "border-box", which calculates the height and width of the element in the same fashion as quirks mode.[22] Internet Explorer 8, Opera 7.0 and later, and Konqueror 3.3.2 support the CSS3 box-sizing property. Mozilla browsers such as Mozilla Firefox support the same functionality using a proprietary "-moz-box-sizing" property [23], and WebKit browsers such as Apple Safari and Google Chrome support it using a proprietary "-webkit-box-sizing" property.[24]
[edit] Box model issues in other areas
While the box model normally only pertains to CSS design, and current versions of most browsers have implemented the standard box model for CSS, a box model issue still exists in another browser feature, namely the definitions of offsetX and offsetY in CSSOM View Module. The CSSOM View Module is used in querying the actual dimensions of rendered elements and mouse positions in JavaScript. The standard specifies the use of "padding box" dimensions for offsetX and offsetY; however, currently, most major browsers use other box models.[25]
[edit] References
- ^ Shafer, Dan (2005). HTML Utopia: Designing Without Tables Using CSS. Melbourne: Sitepoint. pp. 124 & Appendix C. ISBN 0-9579218-2-9. http://www.sitepoint.com/books/css1/errata.php.
- ^ Shea, David; Molly E. Holzschlag (2005). The Zen of CSS Design. Berkeley: Peachpit Press. ISBN 0321303474. http://www.digital-web.com/articles/zen_of_css_design/.
- ^ a b Håkon Wium Lie; Bert Bos (January 11, 1999). "Cascading Style Sheets, level 1". W3C. http://www.w3.org/TR/1999/REC-CSS1-19990111#formatting-model. Retrieved on 2007-06-24.
- ^ "The HTML3 Table Model". W3C. http://www.w3.org/TR/WD-tables-960123."RFC 1942 HTML Tables". http://www.ietf.org/rfc/rfc1942.txt. "The default table width is the space between the current left and right margins."
- ^ http://www.w3.org/TR/REC-html32
- ^ http://www.w3.org/TR/REC-CSS1-961217
- ^ http://www.xs4all.nl/~ppk/css2tests/box.html
- ^ http://www.quirksmode.org/css/box.html
- ^ Johansson, Roger (21 December, 2006). "Internet Explorer and the CSS box model". http://www.456bereastreet.com/archive/200612/internet_explorer_and_the_css_box_model/. Retrieved on 2008-11-12.
- ^ Håkon Wium Lie; Bert Bos (December 17, 1996). "Cascading Style Sheets, level 1". W3C. http://www.w3.org/TR/REC-CSS1-961217#formatting-model. Retrieved on 2006-12-09.
- ^ Lance Silver (March 2001). "CSS Enhancements in Internet Explorer 6". MSDN Library. Microsoft. http://msdn2.microsoft.com/en-us/library/bb250395.aspx#cssenhancements_topic3. Retrieved on 2007-06-24.
- ^ a b Markus Mielke (2006-09-26). "Cascading Style Sheet Compatibility in Internet Explorer 7". MSDN. http://msdn2.microsoft.com/en-us/library/bb250496.aspx. 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."
- ^ "!DOCTYPE". http://msdn.microsoft.com/en-us/library/ms535242(VS.85).aspx. 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."
- ^ Roger Johansson (2006-12-21). "Internet Explorer and the CSS box model". 456 Berea Street. http://www.456bereastreet.com/archive/200612/internet_explorer_and_the_css_box_model/. Retrieved on 2007-01-14.
- ^ Arve Bersvendsen (February 2004). "Hack-free CSS for IE". Arve Bersvendsen's weblog. http://virtuelvis.com/archives/2004/02/css-ie-only. Retrieved on 2007-01-16.
- ^ Vorsprung durch Webstandards | Douglas Bowman declares his love to CSS …
- ^ Vorsprung durch Webstandards | Ethan Marcotte declares his love to CSS …
- ^ CSS2 - Box model tweaking
- ^ CSS Box Model
- ^ Vorsprung durch Webstandards | Peter-Paul Koch declares his love to CSS …
- ^ Box Model Enlightenment, Bernie Zimmermann
- ^ "CSS3 Basic User Interface Module". W3C. http://www.w3.org/TR/css3-ui/#box-sizing.
- ^ "-moz-box-sizing". Developer Center, CSS reference. mozilla.org. 11 April 2009. https://developer.mozilla.org/en/CSS/box-sizing. Retrieved on 2009-04-11. "It is possible to use this property to emulate the behavior of browsers that do not correctly support the CSS box model specification."
- ^ "CSS contents and browser compatibility". quirksmode.org. http://www.quirksmode.org/css/contents.html.
- ^ http://www.quirksmode.org/dom/w3c_cssom.html#t51
[edit] External links
- Tantek Çelik's description of the "box model hack"
- Getting Internet Explorer to Play Well with CSS - article on about.com that outlines various ways to get around box model problem and other IE bugs.
- Cascading Style Sheet Compatibility in Internet Explorer 7 - MSDN article, July 2006.
|