[英]Z-Index Does Not Work on Child Div
Here's the fiddle: http://jsfiddle.net/gBQqQ/ 这是小提琴: http : //jsfiddle.net/gBQqQ/
Here's the html: 这是html:
<div id='testtexture'>
<div id='testinside'>
<div style='vertical-align: top;' class='test'></div>
</div>
</div>
And the css: 和CSS:
.test {
width: 50px;
position: relative;
margin-left: auto;
margin-right: auto;
min-height: 130px;
height:auto;
padding-bottom:50px;
background:blue;
}
#testtexture {
width: 100%;
position: relative;
top: 10px;
}
#testinside {
z-index: 3;
background:red;
position:relative;
}
I do not see why there is an issue. 我不明白为什么会有问题。 I expect either there is something obvious that I am missing, or there is an underlying issue which means I cannot make the red div go above the blue div- maybe because it is a child of the blue div?
我希望我可能缺少一些明显的东西,或者存在一个潜在的问题,这意味着我不能使红色div超过蓝色div,也许是因为它是蓝色div的孩子?
Generally not the best idea to have a child div you want to appear behind it's parent. 通常,最好不要让子div出现在其父级后面。 Usually you would take the child div outside the parent to do this.
通常,您会将孩子div放在父母之外。 Nonetheless it is possible.
尽管如此,还是有可能的。 Add
z-index:-1
to the child div and remove position:relative
from the parent. 将
z-index:-1
添加到子div并从父项中删除position:relative
。
HTML HTML
<div id='testtexture'>
<div id='testinside'>
<div class="test"></div>
</div>
</div>
CSS CSS
.test {
position: relative;
z-index: -1;
width: 50px;
margin: 0 auto;
height: auto;
min-height: 130px;
padding-bottom: 50px;
background: blue; }
#testinside { background: red; }
See fiddle: http://jsfiddle.net/gBQqQ/1/ 参见小提琴: http : //jsfiddle.net/gBQqQ/1/
If you use firebug, you can see div.test
is still there in the correct position behind it's parent. 如果您使用Firebug,则可以看到
div.test
仍然位于父项后面的正确位置。 As a side note, the styling vertical-align
you had on a div won't do anything. 附带说明一下,您在div上设置
vertical-align
样式不会执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.