内边距的折叠

内边距的折叠

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>内边距的折叠</title>
    <style>
        .box1,.box2{
            width: 200px;
            height: 200px;
            font-size: 50px;
        }
        /* 
            垂直方向外边距重叠
            相邻的垂直外边距会发生重叠现象
                兄弟元素:相邻垂直外边距会取两者之间的较大值(两者都是正值)
                        一正一负则取两者的和
                        两个都是负值,取绝对值大的一方折叠
                        对于开发有利,不需要处理


                父子元素:相邻外边距,子元素的会传递给父元素(上外边距)
                        父子外边距的折叠,会影响到页面的布局,必须进行处理
                        处理方法:1.不用外边距   2.不要相邻
         */
        .box1{
            background-color: blanchedalmond;
            margin-bottom: 100px;
        }

        .box2{
            background-color: blue;
            margin-top: 100px;
            /* 没有效果,产生重叠 */
        }

        .box3{
            width: 200px;
            height: 200px;
            background-color: cyan;
        }
        .box4{
            width: 100px;
            height: 100px;
            background-color: brown;
            margin-top: 100px;
        }

        .box5{
            width: 200px;
            height: 100px;
            background-color: rgb(24, 179, 18);
            padding-top: 100px;
        }
        .box6{
            width: 100px;
            height: 100px;
            background-color: rgb(194, 22, 165);
        }

        .box7{
            width: 200px;
            height: 200px;
            background-color: rgb(24, 179, 18);
            border-top: 1px red solid;
        }
        .box8{
            width: 100px;
            height: 100px;
            background-color: rgb(194, 22, 165);
            margin-top: 100px;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>

    <div class="box3">
        <div class="box4"></div>
    </div>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div class="box5">
        <div class="box6"></div>
    </div>


    <br>
    <br>
    <br>
    <br>
    <br>
    <div class="box7">
        <div class="box8"></div>
    </div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值