为什么使用z-index -1时子元素在容器后面?

问题描述 投票:0回答:1
[我正在容器内部工作,并且将另外两个元素作为父子元素。当我用z-index: -1将子元素设为绝对时,子元素将位于容器后面。我想要的是让它放在父母的后面。

Js Fiddle Example

<div class="container"> Container<br><br> <div class="paremt"> Parent position relative <div class="child"> Parent child Position Absolute index -1 </div> </div> </div>

* {
  color: #fff;
  font-size: 20px;
}
.container{
  background-color: pink;
  width: 100%;
  height: 150px;
}
.paremt{
  position: relative;
  background-color: red;
  height: 80px;
}
.child{
  position: absolute;
  top: 0;
  left: -20px;
  z-index: -1;
  background-color: blue;
  width: 400px;
  height: 200px;
  line-height: 250px;
}
[我正在容器内部工作,并且将另外两个元素作为父子元素。当我使用z-index将子元素设为绝对时:-1子元素在容器后面。我想要的是让它放在...
css element z-index parent
1个回答
0
投票
添加您的父母

0
投票
您只需要添加
© www.soinside.com 2019 - 2024. All rights reserved.