09 元素的层级

    技术2022-07-12  74

    <!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>
    Processed: 0.011, SQL: 9