People slowly realized that the traditional box model was not straightforward, so they added a new CSS property called box-sizing
.
box-sizing:
Box size,Box model.
##We often encounter that the width of the left and right modules is 50%. Adding a border will cause it to fall. Adding this style can solve the problem. Take a look at the chestnut:
<!DOCTYPE html><html><head><style> p.container{width:300px;border:10px solid blue;}p.box{box-sizing:border-box;-moz-box-sizing:border-box; /* Firefox */-webkit-box-sizing:border-box; /* Safari */width:50%;height:80px;padding:10px;border:10px solid red;float:left;}</style></head><body><p class="container"><p class="box">这个 p 占据左半部分。</p><p class="box">这个 p 占据右半部分。</p><p style="clear:both;"></p></p></body></html>
<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 #186645; 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>