当一个父盒子里面有一个子盒子,当子盒子设置了margin-top:50px;这时候父盒子会掉下去,子盒子的margin-top不会掉下去
(1)没加margin-top值时
![](https://img-blog.csdnimg.cn/img_convert/c8903fe0590a2f0ccb1d1a096d666635.png)
![](https://img-blog.csdnimg.cn/img_convert/623eb2759b3aea0cb51e5283be3f1855.png)
![](https://img-blog.csdnimg.cn/img_convert/240149f472c32888bc2ceab33da7d70e.png)
(2)给son加margin-top值后
![](https://img-blog.csdnimg.cn/img_convert/dc0e3bb96c3e5a8816c99d264da4990e.png)
![](https://img-blog.csdnimg.cn/img_convert/8d59045dde61dc3b2b30c09bf5e05781.png)
影响父盒子,box盒子掉下来了
注意:给son加margin-left(margin-right同理)值不会影响父盒子box
![](https://img-blog.csdnimg.cn/img_convert/cf4fec087bdbc49ec0ed3745b44740b0.png)
![](https://img-blog.csdnimg.cn/img_convert/bf89b25f028e6ea241a7b7c6457e9a1a.png)
(3)解决的方法
第一种:给父盒子添加overflow:hidden(推荐使用的方法)
![](https://img-blog.csdnimg.cn/img_convert/0bc511aaaf93ed96e162006fa7edbfa8.png)
![](https://img-blog.csdnimg.cn/img_convert/2dbacc8ddf2f5236536a554a918241de.png)
第二种:给父盒子添加float:left;(不太建议使用)
![](https://img-blog.csdnimg.cn/img_convert/6eed8db7d607d8634cef5da34ce85516.png)
第三种:给父盒子加边框 border:1px solid red;(不推荐使用,会增加盒子的大小)
![](https://img-blog.csdnimg.cn/img_convert/3b76d4854c4667088a98889b9f96faed.png)
有两个盒子,一个盒子设置下边距margin-bottom,一个盒子设置上边距margin-top
(1)正常情况下
![](https://img-blog.csdnimg.cn/img_convert/6340ae5731ae796ec5f6671cffa92dc2.png)
![](https://img-blog.csdnimg.cn/img_convert/6be20ebbf7cdd59666958ff35ac2c691.png)
![](https://img-blog.csdnimg.cn/img_convert/c59085c2f40be21d65ea1c5d80024df6.png)
(2)给left加下边距margin-bottom;
![](https://img-blog.csdnimg.cn/img_convert/9870fa484946469b1b4ed879e4322505.png)
![](https://img-blog.csdnimg.cn/img_convert/a82de2cf9e3297799998946f8effca34.png)
(3)给right加上边距margin-top
![](https://img-blog.csdnimg.cn/img_convert/43c964ae820b46f730c4900dc244b4c8.png)
![](https://img-blog.csdnimg.cn/img_convert/340224f7b676600cd3ab4689e3a3bd12.png)
上面三个都是正常没有报错的
(4)left加上下边距margin-bottom,right加上上边距margin-top,
![](https://img-blog.csdnimg.cn/img_convert/e62405ac950f854d54374ae60d62b220.png)
![](https://img-blog.csdnimg.cn/img_convert/a801f765a35516299ebe0a9c22f29f7c.png)
![](https://img-blog.csdnimg.cn/img_convert/4b9da7d0461ad650127bb1250fbe32e6.png)
这个是left盒子的下边框
![](https://img-blog.csdnimg.cn/img_convert/b6b0518ca63f540042b0080b495436a2.png)
这是right盒子的上边框
可以看到,两个盒子的边框重叠了,本来应该是margin-bottom + margin+top = 100px,但是实际上他们的边框只有50px,并且当有一个边框值比较大时,盒子的边框的取值会取最大值。
例如
![](https://img-blog.csdnimg.cn/img_convert/228ba649d5dedaafee8930e5e552fb99.png)
![](https://img-blog.csdnimg.cn/img_convert/400d24191bdc1332795dd8c03e079dce.png)
![](https://img-blog.csdnimg.cn/img_convert/dace897d743e12db533298901ea424de.png)