Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.