I constantly use box-sizing: border-box; on all elements when creating CSS files, ie
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
However I cannot seem to get this to work with the file 'Normalize.css' (https://github.com/necolas/normalize.css)
I have tried adding the above code to the top of my own CSS file, within normalize itself, but have been unsuccessful
I would very much like to utilise normalize.css as it is not as drastic as some other CSS reset files, but how do I make it accept box-sizing: border-box; so that it effects all elements and is cross browser friendly?
There are two ways to use Normalize in a project: edit the source to customize your own Normalize stylesheet, or use it as a base and add styles on top. The former is a pick-and-choose strategy where you go through the Normalize. css file and delete whatever you don't need to make your own custom stylesheet.
With the CSS box-sizing Property The box-sizing property allows us to include the padding and border in an element's total width and height. If you set box-sizing: border-box; on an element, padding and border are included in the width and height: Both divs are the same size now!
border-box tells the browser to account for any border and padding in the values you specify for an element's width and height. If you set an element's width to 100 pixels, that 100 pixels will include any border or padding you added, and the content box will shrink to absorb that extra width.
The best way I have seen so far of getting box-sizing working is:
html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
*,
*::before,
*::after {
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
If your CSS reset (normalize.css) is inserted at the very top of your stylesheet, with this rule just after normalize, all should work as expected.
The rule above allows easier control over setting box-sizing: content-box
for things like third party widgets.
For more information on this technique, I'd recommmend: https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/ or http://www.paulirish.com/2012/box-sizing-border-box-ftw/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With