2019-07-07
描述
重置盒子模型,使 width 和 height 不会被他们的 border 或 padding 所影响。
HTML
<div class="box">border-box</div>
<div class="box content-box">content-box</div>
CSS
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
.box {
display: inline-block;
width: 150px;
height: 150px;
padding: 10px;
background: tomato;
color: white;
border: 10px solid red;
}
.content-box {
box-sizing: content-box;
}
Demo
说明
box-sizing: border-box使附加的padding或border样式不会改变一个元素的width或heightbox-sizing: inherit使一个元素能够继承他父亲的box-sizing规则
浏览器支持
支持率:99.9%
支持情况:https://caniuse.com/#feat=css3-boxsizing
ME!
链滴