外边距的折叠
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>外边距的折叠</title> <style type="text/css"> /* 垂直方向相邻的外边距,会发生外边距折叠现象,兄弟元素间的相邻外边距,会取两个 外边距间最大值(正值) 如果是负外边距,则取绝对值较大的 一正一负,取两个值的和 父子元素的相邻垂直外边距,子元素的外边距会传递给父元素 */ .box{ height: 50px; width: 50px; border: double; background-color: #87CEEB; } .box1{ height: 100px; width: 100px; border: 2px solid red; margin-top:150px; margin-bottom: 100px; /* margin-bottom: -50px; */ } .box2{ width: 200px; height: 200px; border: solid; margin-top: 50px; } </style> </head> <body> <div class="box"> <div class="box1"></div> <div class="box2"></div> </div> </body> </html>
本文来自博客园,作者:氯丙嗪,转载请注明原文链接:https://www.cnblogs.com/YcxyH/p/16249335.html