Merge pull request #21 from joshbader/box-sizing-reset
[FEATURE] Adding box-sizing-reset snippet.
This commit is contained in:
46
snippets/box-sizing-reset.md
Normal file
46
snippets/box-sizing-reset.md
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
### Box-sizing reset
|
||||||
|
|
||||||
|
Resets the box-model so that `width`s and `height`s are not affected by their `border`s or `padding`.
|
||||||
|
|
||||||
|
#### CSS
|
||||||
|
|
||||||
|
```css
|
||||||
|
.html {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: inherit;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Demo
|
||||||
|
|
||||||
|
<div class="snippet-demo">
|
||||||
|
<div class="snippet-demo__box-sizing-reset">Demo</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.snippet-demo__box-sizing-reset {
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: 200px;
|
||||||
|
padding: 1.5em;
|
||||||
|
color: #000;
|
||||||
|
font-family: sans-serif;
|
||||||
|
background-color: #ccc;
|
||||||
|
border: 5px solid;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
#### Explanation
|
||||||
|
|
||||||
|
1. `box-sizing: border-box` makes the addition of `padding` or `border`s not affect an element's `width` or `height`.
|
||||||
|
2. `box-sizing: inherit` makes an element respect its parent's `box-sizing` rule.
|
||||||
|
|
||||||
|
#### Browser support
|
||||||
|
|
||||||
|
<span class="snippet__support-note">✅ No caveats.</span>
|
||||||
|
|
||||||
|
* https://caniuse.com/#feat=css3-boxsizing
|
||||||
Reference in New Issue
Block a user