盒模型
2018-03-16 本文已影响0人
茂茂爱吃鱼
box = margin + border + padding + width/height
两种显示模式
- content-box
width = content - border-box
width = content + padding + border
<!-- 不同盒模型下显示宽度相同 -->
<div class="div1"></div>
<div class="div2"></div>
.div1 {
width: 100px;
height: 100px;
padding: 30px;
margin: 20px;
border: 20px solid red;
background-color: #222;
}
.div2 {
width: 200px;
height: 200px;
padding: 20px;
margin: 20px;
border: 20px solid red;
background-color: #222;
box-sizing: border-box;
}

切换盒模型显示模式
使用CSS中的box-sizing
属性即可