【发布时间】:2015-12-09 21:41:20
【问题描述】:
我有一个嵌套在z-index: 0 元素内的元素,该元素位于z-index: 1 元素的下方。该父元素*正确地**显示在另一个元素下。但是,当我创建子元素 display: table-cell; z-index: 2 时,它会跳出它的父元素(在垂直 z 轴上)并在更高的外部元素之上!为什么会发生这种情况,我该如何阻止它?
示例:http://jsfiddle.net/5x8jy74o/
父级为display: table 的示例,同样的问题:http://jsfiddle.net/5x8jy74o/1/
HTML:
<div class="hover">
HOVER IN HERE
</div>
<div class="container">
<div class="tc">
This should be under
</div>
</div>
CSS:
.hover
{
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100px;
background-color: #e8e8e8;
z-index: 1;
}
.container
{
position: relative;
top: 0px;
left: 0px;
width: 100px;
height: 100px;
background-color: red;
}
.tc
{
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 50px;
background-color: blue;
display: table-cell;
z-index: 2;
}
【问题讨论】: