Internet Explorer box model bug

From Seo Wiki - Search Engine Optimization and Programming Languages
Jump to navigationJump to search
File:W3C and Internet Explorer box models.svg
The difference in how width is interpreted between the W3C and Internet Explorer box models

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.

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]

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]

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
  • When 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, causing undesired results in pages using these hacks.[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]

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 and later 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]

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]

References

  1. 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. 
  2. 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/. 
  3. 3.0 3.1 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 2007-06-24. 
  4. "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." 
  5. http://www.w3.org/TR/REC-html32
  6. http://www.w3.org/TR/REC-CSS1-961217
  7. http://www.xs4all.nl/~ppk/css2tests/box.html
  8. http://www.quirksmode.org/css/box.html
  9. 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 2008-11-12. 
  10. 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 2006-12-09. 
  11. 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 2007-06-24. 
  12. 12.0 12.1 Markus Mielke (2006-09-26). "Cascading Style Sheet Compatibility in Internet Explorer 7". MSDN. http://msdn2.microsoft.com/en-us/library/bb250496.aspx. Retrieved 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."
  13. "!DOCTYPE". http://msdn.microsoft.com/en-us/library/ms535242(VS.85).aspx. Retrieved 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."
  14. 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 2007-01-14. 
  15. Arve Bersvendsen (February 2004). "Hack-free CSS for IE". Arve Bersvendsen's weblog. http://virtuelvis.com/archives/2004/02/css-ie-only. Retrieved 2007-01-16. 
  16. Vorsprung durch Webstandards | Douglas Bowman declares his love to CSS …
  17. Vorsprung durch Webstandards | Ethan Marcotte declares his love to CSS …
  18. CSS2 - Box model tweaking
  19. CSS Box Model
  20. Vorsprung durch Webstandards | Peter-Paul Koch declares his love to CSS …
  21. Box Model Enlightenment, Bernie Zimmermann
  22. "CSS3 Basic User Interface Module". W3C. http://www.w3.org/TR/css3-ui/#box-sizing. 
  23. "-moz-box-sizing". Developer Center, CSS reference. mozilla.org. 11 April 2009. https://developer.mozilla.org/en/CSS/box-sizing. Retrieved 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." 
  24. "CSS contents and browser compatibility". quirksmode.org. http://www.quirksmode.org/css/contents.html. 
  25. http://www.quirksmode.org/dom/w3c_cssom.html#t51

External links

es:Internet Explorer box model bug pl:Internet Explorer box model bug

If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...