818 B
818 B
Clearfix
Resets the box-model so that widths and heights are not affected by their borders and/or padding.
CSS
.html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
Demo
Demo
<style>
.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
box-sizing: border-boxmakes the addition ofpaddingorborders not affect an elementswidthand/orheight.box-sizing: inheritmakes an element respect its parentsbox-sizingrule.
Browser support
✅ No caveats.