Home > Article > Web Front-end > CSS3:box-sizing: No more worrying about the box model_html/css_WEB-ITnose
Off topic:
The standard pursued by W3C is content-box, which requires calculation of borders, padding and content; but personally,
I prefer the traditional IE6 Weird mode, no need to consider whether the container will be stretched (disrupting the layout);
W3C standard box = (border padding content block size), drag Moves the whole body in one move;
Traditional IE6 box = overall width and height (border, padding and adjustment with the size of the box)
If the occupied position is calculated, both boxes must include margin (Margin)
In short, the W3C standard box needs to add various sizes to get the overall width and height, while traditional IE6 subtracts the intrinsic element size from the whole to achieve the adjustment effect
CSS3: box-sizingbox-sizing : content-box | border-box | inherit;, there is also a padding-box for Firefox, which is almost useless!!!
Simple code, three boxes
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>box-sizing</title> <style> .demo1,.demo2,.demo3{ width:200px; height:200px; background-color: #2277AD; margin:20px; } .demo1{ box-sizing: content-box; border:30px solid #12D732; padding:10px; } .demo2{ box-sizing: border-box; border:30px solid #12D732; padding:10px; } .demo3{ box-sizing: padding-box; border:30px solid #12D732; padding:10px; } </style></head><body> <div class="demo1"> 我是盒子内部的内容啊!! </div> <div class="demo2"> 我是盒子内部的内容啊!! </div> <div class="demo3"> 我是盒子内部的内容啊!! </div></body></html>
Standard boxes also have their advantages. The size of the content block can be controlled in a targeted manner... Very detailed adjustments are required, but the calculation is more troublesome