Skip to content

Instantly share code, notes, and snippets.

@bouveng
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bouveng/6ea86457738355a9ab30 to your computer and use it in GitHub Desktop.
Save bouveng/6ea86457738355a9ab30 to your computer and use it in GitHub Desktop.
A box model that makes sense
This is my favorite CSS addition. Before the box-sizing property, if you had an element with
a defined width of 250px and added 25px padding (both left and right) to it, the actual width
would become 300px. This always seemed strange to me and when combined with making sites
responsive, it would really become a pain in the ass. Fortunately we can now change how the
box model calculates an element’s width and height. Using box-sizing: border-box will include
the element’s border and padding when calculating the height and width of an element. Using
our previous example, an element with box-sizing: border-box applied to it with a defined
width of 250px and padding of 25px will remain 250px wide.
To apply this behavior to all of your elements, include this at the top of your stylesheet:
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
Source: http://sawyerhollenshead.com/writing/css-tips-and-techniques/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment