外边距的折叠

相邻的垂直方向外边距会发生重叠

 

兄弟元素之间相邻的垂直方向谁大听谁的,一正一负去两者和,如果是两个负数,去绝对值大的

 

父子元素

父子元素之间的相邻外边距,子元素会传递给父元素。(上外边距)

父子外边距一个折叠,会影响页面的布局

解决方案:使用padding隔开,不是很完美的方式

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            width: 200px;
            height: 199px;
            font-size: 100px;
        }

        .box1 {
            background-color: chocolate;
            border-top: 1px red solid;
        }

        .box3 {
            width: 100px;
            height: 99px;
            background-color: crimson;
            margin-top: 100px;

        }
    </style>
</head>

<body>
    <div class="box1">
        <div class="box3">

        </div>
    </div>

</body>

</html>

 

posted @ 2021-02-17 11:27  俗气小博  阅读(69)  评论(0)    收藏  举报