Quick Tip: Did Internet Explorer get the Box Model Right?
Tutorial Details
- Completion Time: 5 Minutes
The CSS standard states that borders and padding should be applied on top of the specified width of an element. As such, if I have a 200px div, and apply 40px worth of borders and padding, total, the width will then be 240px. This makes perfect sense; however, Internet Explorer actually did things differently. They adopted a model where the maximum width is what you specified. The borders and padding are then factored into that width, reducing the content area. As a result, the width of the element never exceeds the stated width of 200px.
As we mostly work with extremely sensitive floated layouts, where even the addition of a 1px border can break the design, I wonder: did Internet Explorer get it right?
Subscribe to our YouTube page to watch all of the video tutorials!
Prefer to watch this video on Screenr?
Box Sizing
“The box-sizing CSS property is used to alter the default CSS box model used to calculate widths and heights of elements. It is possible to use this property to emulate the behavior of browsers that do not correctly support the CSS box model specification.”
This means that, if you should decide that you want to mimic Internet Explorer’s original interpretation of the box model, you can. The default value for box-sizing is “content-box.” This simply means that the width and height of an element do not include the borders and padding (or margins).
By changing this value to “border-box,” the width and height values then include the borders and padding.
#box {
width: 200px;
height: 200px;
background: red;
padding: 10px;
border: 10px solid black;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
Because we’ve declared box-sizing with a value of “border-box,” the final width of the #box element, styled above, will be 200px.
Especially for floated layouts, this can save you a lot of headaches! But with that said, I’m still undecided. What are your thoughts on Internet Explorer’s interpretation of the box model?
- http://www.scottnelle.com/ Scott Nellé
- Steffen Wieprecht
- http://www.umbraprojekt.pl mingos
- http://blackmesalabs.com Leo
- http://www.pataltechnologies.com Tom
- http://diegop.com Diegop
- http://slightlymore.co.uk/ Clinton Montague
- foljs
- http://jamesmcminn.com James McMinn
- http://thinktankdesign.ca Robert Hurst
- http://webkicks.dotink.org Matthew J. Sahagian
- Andy
- http://webkicks.dotink.org Matthew J. Sahagian
- farfique
- samarjit
- http://ryan.thejenks.me Ryan
- http://tyfujimura.com Ty Fujimura
- http://www.pixelfuelmedia.com/ Johnny Freeman
- David C
- http://www.alfystudio.com Ahmad Alfy
- http://ingo-fahrentholz.com Ingo Fahrentholz
- Will Moyer
- Will Moyer
- http://www.digitalvaldosta.com Digitalvaldosta
- Grant
- http://www.xcellence-it.com/ Xcellence IT
- Vishu
- Sathish
- Fatih
- Callum
- http://www.ifadey.com Fawad Hassan
- http://www.myunv.com/ Sunny Singh
- http://www.martin-mates.cz Martin Mates
- http://www.alfystudio.com Ahmad Alfy
- Chris
- http://craigps.info/ Craigsnedeker
- Dave
- Dan
- Carlos
- http://www.dynamicguru.com Mujtaba Ahmed
- Chris Sanders
- JT
- http://jacobdubail.com Jacob
- http://www.arvindandrion.com arvind
- http://www.zingocan.com Tayfun ÇAKIR
- Dave
- http://www.twitter.com/isJohnny Johnny
- Mauro
- http://www.ronniesan.com RonnieSan
- Josh
- http://twitter.com/ilovecomputers ilovecomputers
- http://saurini.com Rob
- Markus
- http://novatvmedia.com/retropinups Anthony Alexander
- http://www.buitenaardig.nl/ Phil
- http://jasonnorriswebdesign.com Jason
- http://coltpini.com Colt Pini
- http://www.conceptify.com Joel
- http://coltpini.com Colt Pini
- Jim Nech
- Joacim Boive
- http://www.webuddha.com/ David H
- http://jethrolarson.github.com Jethro Larson
- wison
- wison
- Ernest Jumbe
- http://coltpini.com Colt Pini
- http://visuex.com Michael Tunnell
- http://coltpini.com Colt Pini
- http://www.arvag.net GaVrA
- Seth
- http://yongbakos.com Yong
