css中盒模型的注意点

发布日期:2023-05-26 浏览次数:1

1、padding不能为负值,margin可以。

2、背景色会平铺到非margin区域。

背景色会平铺到content、padding、border部分。

3、marked在Flexbox或网格布局中,不存在margin-top、bottom叠加及margin-top传递现象。

css盒模型实例

.box1 {
     width: 200px;
     height: 200px;
     background: pink;
     margin-bottom: 30px;
     取最高值,所以两个margin叠加,是30px
}
.box2 {
     width: 100px;
     height: 100px;
     background: blue;
     margin-top: 20px;
}
如果您有什么问题,欢迎咨询技术员 在线沟通