图:元素堆叠演示
值 | 描述 |
---|---|
auto | 默认值,堆叠顺序与父元素相等 |
number | 使用具体数值(整数)设置元素的堆叠顺序 |
inherit | 从父元素继承 z-index 属性的值 |
<!DOCTYPE html> <html> <head> <style> .box-x { width: 150px; height: 350px; border: 1px dashed red; background-color: rgba(255, 153, 153, 0.7); float: left; } .box-y { width: 300px; height: 120px; border: 1px dashed green; background-color: rgba(179, 255, 153, 0.7); } .one { position: absolute; top: 5px; left: 5px; z-index: 4; } .two { position: relative; top: 30px; left: 80px; z-index: 3; } .three { position: relative; top: -10px; left: 120px; z-index: 2; } .four { position: absolute; top: 5px; right: 5px; z-index: 1; } .five { margin-left: 100px; margin-top: -50px; background-color: rgba(255, 255, 153, 0.7); z-index: 5; } </style> </head> <body> <div class="box-x one">one</div> <div class="box-y two">two</div> <div class="box-y three">three</div> <div class="box-x four">four</div> <div class="box-y five">five</div> </body> </html>运行结果如下图所示:
图:z-index 属性演示
本文链接:http://task.lmcjl.com/news/14637.html