五、内减盒模型

五、内减盒模型

之前我们的盒模型:书写width height 再写padding border margin ,是外扩盒模型

css3新增加的内减盒模型

5.1 box-sizing:border-box

书写了width height 再设置padding border ,盒子占有不会变大,padding border是在内容宽高基础上内减的。

1
2
3
4
5
6
7
8
9
.box {
width: 200px;
height: 200px;
padding: 50px;
border: 10px solid #000;
background-color: lightblue;
/* 内减盒模型 */
box-sizing: border-box;
}

NIUm1e.png

一旦书写了box-sizing:border-box

width height 表示盒子占有的宽高

5.2 应用

应用在有边框有padding盒子的均分

1
2
3
4
5
6
7
8
9
10
.box p {
float: left;
/* 实际宽度50% */
width: 50%;
height: 200px;
background-color: green;
padding: 0px 50px;
/* 内减盒模型 */
box-sizing: border-box ;
}

NIUY9S.png

点击查看

本文标题:五、内减盒模型

文章作者:Mango

发布时间:2020年06月30日 - 21:38:42

最后更新:2020年06月30日 - 21:44:19

原始链接:https://mango185.github.io/post/346324a4.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------------本文结束 感谢您的阅读-------------------