【发布时间】:2014-07-07 18:42:16
【问题描述】:
如何把父div放在前面?
我的 html:-
<div class="main">
<div class="parent">
<div class="child"></div>
</div>
</div>
我的 CSS :-
.main{
width : 400px;
height: 400px;
background : green;
z-index: 10;
}
.parent{
width: 100px;
height: 100px;
position: relative;
background: yellow;
z-index: 5;
}
.child{
width : 200px;
height: 200px;
background: red;
z-index : -1;
}
我的 js 小提琴: http://jsfiddle.net/gautm5154/xPvHf/
【问题讨论】:
-
您为什么要这样做?在这种情况下,您只需交换父母和孩子,不是吗?
-
不可能,父元素总是在他的子元素之下。没有机会将父级的 z-index 设置为高于子级(ren)。
-
@panther 在下面查看我的答案。