The "box-sizing: border-box" means less complex math for grid designs!

One of the least enjoyable aspects of current website design is the need to add and subtract padding (or is it margin and also the border) from the width of elements in CSS design layouts. This post from Paul Irish goes into the border-box model and it's support in browsers.

One of my least favorite parts about layout with CSS is the relationship of width and padding. You're busy defining widths to match your grid or general column proportions, then down the line you start to add in text, which necessitates defining padding for those boxes. And 'lo and behold, you now are subtracting pixels from your original width so the box doesn't expand.

Ugh. If I say the width is 200px, gosh darn it, it's gonna be a 200px wide box even if I have 20px of padding. So as you know, this is NOT how the box model has worked for the past ten years. Wikipedia has a great history of this box model. Jeff Kaufman also dove into the history

Anyway, I have a recommendation for your CSS going forward:

*{ 
-moz-box-sizing: border-box; 
-webkit-box-sizing: border-box; 
box-sizing: border-box;
}

This gives you the box model you want. Applies it to all elements. Turns out many browsers already use border-box for a lot of form elements (which is why inputs and textareas look diff at width:100%;) But applying this to all elements is safe and wise.

http://paulirish.com/2012/box-sizing-border-box-ftw/ (via David Hinson)

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Month List

Page List