CSS box model: Difference between revisions

Content deleted Content added
Bluelinking 2 books for verifiability.) #IABot (v2.1alpha2
Monkbot (talk | contribs)
m Task 16: replaced (5×) / removed (0×) deprecated |dead-url= and |deadurl= with |url-status=;
Line 68:
[[Internet Explorer]] in "[[quirks mode]]" includes the content, padding and borders within a specified width or height; this results in a narrower or shorter rendering of a box than would result following the standard behavior.<ref>{{Cite web| url=http://msdn2.microsoft.com/en-us/library/bb250395.aspx#cssenhancements_topic3 | title=CSS Enhancements in Internet Explorer 6 | author=Lance Silver |date=March 2001 | publisher=[[Microsoft]] | work=[[Microsoft Developer Network]] | accessdate=2007-06-24}}</ref>
 
The ''Internet Explorer box model'' behavior was often considered a bug, because way in which earlier versions of [[Internet Explorer]] handle the [[CSS box model|box model]] or sizing of elements in a web page, which differs from the standard way recommended by the [[W3C]] for the [[Cascading Style Sheets]] language.<ref>{{Cite book |title=HTML Utopia: Designing Without Tables Using CSS |last=Shafer |first=Dan |year=2005 |publisher=[[Sitepoint]] |___location=Melbourne |isbn=0-9579218-2-9 |pages=124 & Appendix C |url=https://archive.org/details/htmlutopia000dans }}</ref><ref>{{Cite book |title=The Zen of CSS Design |last=Shea |first=David |authorlink=Dave Shea (web designer) |author2=[[Molly E. Holzschlag]] |year=2005 |publisher=Peachpit Press |___location=Berkeley |isbn=0-321-30347-4 |url=https://archive.org/details/zenofcssdesignvi00shea |deadurlurl-status=yesdead |df=dmy-all }}</ref> As of [[Internet Explorer 6]], the browser supports an alternative rendering mode (called the "standards-compliant mode") which solves this discrepancy. However, for backward compatibility reasons, all versions still behave in the usual, non-standard way by default (see [[quirks mode]]). [[Internet Explorer for Mac]] is not affected by this non-standard behavior.
 
===Workarounds===
Line 81:
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 it parses CSS rules. The implementation of these CSS "hacks" has been further complicated by the public release of Internet Explorer&nbsp;7, which has had some issues fixed, but not others, causing undesired results in pages using these hacks.<ref name="msdn IE7 blog"/>
 
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 hack|CSS filter]]s to work around the box model bug in older versions of Internet Explorer.<ref name=RJ1 /><ref>{{Cite web | url=http://virtuelvis.com/archives/2004/02/css-ie-only | title=Hack-free CSS for IE | author=Arve Bersvendsen | date=February 2004 | work=Arve Bersvendsen's weblog | accessdate=2007-01-16 | deadurlurl-status=yesdead | archiveurl=https://web.archive.org/web/20070115183512/http://virtuelvis.com/archives/2004/02/css-ie-only | archivedate=15 January 2007 | df=dmy-all }}</ref>
 
==Support for Internet Explorer's box model==
Web designer Doug Bowman has said that the original Internet Explorer box model represents a better, more logical approach.<ref>{{Cite web |url=http://www.vorsprungdurchwebstandards.de/interviews/fallinginlovewithcss/douglas-bowman/ |title=Vorsprung durch Webstandards &#124; Douglas Bowman declares his love to CSS |publisher=Vorsprungdurchwebstandards.de |accessdate=2010-07-07 |archive-url=https://web.archive.org/web/20100614070042/http://www.vorsprungdurchwebstandards.de/interviews/fallinginlovewithcss/douglas-bowman/ |archive-date=2010-06-14 |dead-url-status=yesdead }}</ref> Peter-Paul Koch gives the example of a physical box, whose dimensions always refer to the box itself, including potential padding, but never its content.<ref name="CSS2 - Box model tweaking"/> He 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.<ref>{{Cite web |url=http://www.vorsprungdurchwebstandards.de/interviews/fallinginlovewithcss/peter-paul-koch/ |title=Vorsprung durch Webstandards &#124; Peter-Paul Koch declares his love to CSS |publisher=Vorsprungdurchwebstandards.de |accessdate=2010-07-07 |archive-url=https://web.archive.org/web/20100227061437/http://www.vorsprungdurchwebstandards.de/interviews/fallinginlovewithcss/peter-paul-koch/ |archive-date=2010-02-27 |dead-url-status=yesdead }}</ref> Bernie Zimmermann says that the Internet Explorer box model is closer to the definition of cell dimensions and padding used in the HTML table model.<ref>{{Cite web |url=http://www.bernzilla.com/item.php?id=33 |title=Box Model Enlightenment, Bernie Zimmermann |publisher=Bernzilla.com |date=4 April 2003 |accessdate=2010-07-07 |archive-url=https://web.archive.org/web/20101227135212/http://www.bernzilla.com/item.php?id=33 |archive-date=27 December 2010 |dead-url-status=yesdead }}</ref>
 
The W3C has included a "box-sizing" property in CSS3. When <code>box-sizing: border-box;</code> is specified for an element, any padding or border of the element is drawn ''inside'' the specified width and height, "as commonly implemented by legacy HTML user agents".<ref>{{Cite web| url=http://www.w3.org/TR/css3-ui/#box-sizing | title=CSS3 Basic User Interface Module | publisher=[[World Wide Web Consortium]]}}</ref> [[Internet Explorer 8]], [[WebKit]] browsers such as [[Safari (web browser)|Apple Safari]] 5.1+ and [[Google Chrome]], [[Gecko (layout engine)|Gecko-based]] browsers such as [[Mozilla Firefox]] 29.0 and later, [[Opera (web browser)|Opera]] 7.0 and later, and [[Konqueror]] 3.3.2 and later support the CSS3 box-sizing property. Gecko browsers previous than 29.0 support the same functionality using the browser-specific <code>-moz-box-sizing</code> property.<ref>{{Cite web|url=https://developer.mozilla.org/en/CSS/box-sizing |title=-moz-box-sizing |accessdate=2009-04-11 |work=[[Mozilla Developer Center]] |publisher=[[Mozilla]]|date=11 April 2009 |quote=It is possible to use this property to emulate the behavior of browsers that do not correctly support the CSS box model specification. }}</ref> <code>border-box</code> is the default box model used in [[Bootstrap (front-end framework)|Bootstrap framework]].