盒子模型

75 阅读1分钟

content-box

仅包含宽高,不包含padding、border、margin

.box_content {

    width: 200px;

    height: 200px;

    background-color: blue;

    border: 10px solid yellow;

    box-sizing: content-box;
}

boder-box

其中设置的width、height包括content、padding、border 但并不包含margin

.box_border {

    width: 200px;

    height: 200px;

    background-color: blue;

    border: 10px solid yellow;

    box-sizing: border-box;
}

标准盒子模型与怪异盒子模型区别 标准盒子模型 = margin + border + padding + width (width = content )
IE盒子模型(怪异) = margin + width(width = border + padding + content )

he.png

控制台更加清晰明了:

he1.png

he2.png

可以看出,border-box的最大尺寸是包含了比边距的
content-box最大尺寸是不包含边距,边是裹在外面一圈的