zoukankan      html  css  js  c++  java
  • css z-index的层级关系

    定义和用法

    z-index 属性设置元素的堆叠顺序。拥有更高堆叠顺序的元素总是会处于堆叠顺序较低的元素的前面。

    注释:元素可拥有负的 z-index 属性值。

    注释:Z-index 仅能在定位元素上奏效(例如 position:absolute;)

    说明

    该属性设置一个定位元素沿 z 轴的位置,z 轴定义为垂直延伸到显示区的轴。如果为正数,则离用户更近,为负数则表示离用户更远。

    优先关系

    如果同时出现两个相同的z-index值,那么在后面的元素层级会高于前面的元素。例如:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>z-index</title>
    </head>
    <style type="text/css">
    .first{200px; height: 500px; position: absolute; background:#00f; z-index: 100;}
    .second{250px; height: 250px; position: absolute; background:#f33; z-index: 100;}
    </style>
    <body>
    <div class="first">first</div>
    <div class="second">second</div>
    </body>
    </html>

    类名为second的div会在类名为first的div上面。

    z-index属性是区分所有兄弟元素的高度,并不是所有页面元素的高度;例如:

    <style type="text/css">
    .first{200px; height: 500px; position: absolute; top: 0; background:#00f; z-index: 80;}
    .second{250px; height: 250px; position: absolute; top: 50px; background:#f33; z-index: 100;}
    .first-child{250px; height: 250px; position: absolute; top: 0; background:#333; z-index: 101;}
    </style>
    <body>
    <div class="first">first
    <div class="first-child">first-child
    </div>
    </div>
    <div class="second">second</div>
    </body>

    类名为first-child的div元素的z-index大于类名为second的div元素的z-index;但页面显示效果first-child位于second下面  

  • 相关阅读:
    java新手的session初体验
    菜鸟身份看泛型
    Java初学者不可不知的MyEclipse的设置技巧(自动联想功能)
    GCT之数学公式(几何部分)
    GCT之数学公式(代数部分)
    GCT之语文细节知识
    单元测试的方法
    常用的测试方法
    SQL 经典语句大全
    待处理(一)
  • 原文地址:https://www.cnblogs.com/ypppt/p/12841398.html
Copyright © 2011-2022 走看看