是否可能让孩子的z索引高于其父级

时间:2017-04-26 15:31:29

标签: html css less

代码提取:

<div class="parent">
    <div class="child">

    </div>
</div>

<div class="other">

</div>

我想要做的是将另一个类呈现在父级之上,但是在子级之下是否可以这样做?

1 个答案:

答案 0 :(得分:1)

&#13;
&#13;
.parent {
  width: 300px;
  height: 300px;
  background-color: #F4F4F4;
}

.child {
  width: 200px;
  height: 200px;
  background-color: red;
  border: 4px solid #000;
  opacity: .9;
  
  position: relative;
  z-index: 2;
}

.other {
  width: 150px;
  height: 150px;
  background-color: green;
  border: 4px solid #000;
  opacity: .9;
  
  position: absolute;
  top: 150px;
  z-index: 1;
}
&#13;
<div class="parent">
    <div class="child">

    </div>
</div>

<div class="other"></div>
&#13;
&#13;
&#13;