box-sizing属性可以为三个值之一:content-box(default),border-box,padding-box。
content-box,border和padding不计算入width之内
padding-box,padding计算入width内
border-box,border和padding计算入width之内,其实就是怪异模式了~
ie8+浏览器支持content-box和border-box;
ff则支持全部三个值。
使用时:
-webkit-box-sizing: 100px; // for ios-safari, android
-moz-box-sizing:100px; //for ff
box-sizing:100px; //for other
<style type="text/css">
.content-box{
box-sizing:content-box;
-moz-box-sizing:content-box;
width: 100px;
height: 100px;
padding: 20px;
border: 5px solid #E6A43F;
background: blue;
}
.padding-box{
box-sizing:padding-box;
-moz-box-sizing:padding-box;
width: 100px;
height: 100px;
padding: 20px;
border: 5px solid #;
background: red;
}
.border-box{
box-sizing:border-box;
-moz-box-sizing:border-box;
width: 100px;
height: 100px;
padding: 20px;
border: 5px solid #3DA3EF;
background: yellow;
}
</style>
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQgAAAGJCAIAAAD5eDrVAAAG6UlEQVR4nO3asY0lZRSE0RcGyaC1SIXEIDbcDWHwcCihEnO12/PqfKoAWrr/8fr1IelfvX72B0hPDAwpBIYUAkMKgSGFwJBCYEghMKQQGFIIDCkEhhQCQwqBIYU+BeOvP7/Zl97RK3rDwJje0St6w8CY3tEresPAmN7RK3rDwJje0St6wy5hvF4f9vCBUQbG1sAoA2NrYJSBsTUwysDYGhhlYGwNjDIwtgZGGRhbA6MMjK2BUQbG1sAoA2NrYJSBsTUwysDYGhhlYGwNjDIwtgZGGRhbA6MMjK2BUQbG1sAoA2NrYJSBsTUwysDYGhhlYGwNjDIwtgZGGRhbA6MMjK2BUQbG1sAoA2NrYJSBsTUwysDYGhhlYGwNjDIwtgZGGRhbA6MMjK2BUQbG1sAoA2NrYJSBsTUwysDYGhhlYGwNjDIwtgZGGRhbA6MMjK2BUQbG1sAoA2NrYJSBsTUwysDYGhhlYGwNjDIwtgZGGRhbA6MMjK2BUQbG1sAoA2NrYJSBsTUwysDYGhhlYGwNjDIwtgZGGRhbA6MMjK2BUQbG1sAoA2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