09 元素的层级

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box1,.box2,.box3{
            width: 200px;
            height: 200px;
        }
        .box1{
            background-color: royalblue;
            position: absolute;
        }
        .box2{
            background-color: rgb(245, 30, 7);
            position: absolute;
            top: 50px;
            left: 50px;
        }
        .box3{
            background-color: seagreen;
            position: absolute;
            top: 100px;
            left: 100px;
        }
        /* 
        后设置position的层级高
        但是我们可以通过设置z-index的数值,来来调整层级,数值越高,层级越高
        注意:祖先元素的层级在高,也不会盖住子元素
         */
         .m{
             width: 300px;
             height: 300px;
             background-color: rgb(235, 228, 224);
             position: relative;
             margin-top: 300px;
         }
         .box4,.box5,.box6{
            width: 200px;
            height: 200px;
        }
        .box4{
            background-color: royalblue;
            position: absolute;
            z-index: 3;
        }
        .box5{
            background-color: rgb(245, 30, 7);
            position: absolute;
            top: 50px;
            left: 50px;
            z-index: 2;
           
        }
        .box6{
            background-color: seagreen;
            position: absolute;
            top: 100px;
            left: 100px;
            z-index: 1;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <br>
    <br>
    <div class="m">
        <div class="box4"></div>
        <div class="box5"></div>
        <div class="box6"></div>
    </div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值