box-sizing的使用

HTML:

<div class="box"></div>

CSS

.box{
    box-sizing: border-box;
    /*box-sizing: content-box;*/
    /*box-sizing: inherit;*/
    width: 80px;
    background-color: #0055aa;
    margin: 30px;
    border: 20px solid #008200;
    padding: 10px;
}

盒子模型

標準盒子模型

標準盒子模型

IE盒子模型

IE盒子模型

border-box:

標準盒模型

div總寬/高 = width/height,div主體content寬/高 = width/height - padding(left + right)/(top + bottom) - border(left + right)/(top + bottom)

border-box

border-box

IE盒模型

content-box

標準盒模型

div總寬/高 = width/height + padding(left + right)/(top + right) + border(left + right)/(top + bottom),div主體content寬/高 = width/height

content-box

content-box

inherit

標準盒模型

div總寬/高 = width/height,div主體content寬/高 = width/height - padding(left + right)/(top + bottom) - border(left + right)/(top + bottom)

inherit

inherit

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章