【发布时间】:2016-08-05 19:26:15
【问题描述】:
当我的拖放事件开始时,我需要覆盖一个子 div 以覆盖它的父 div,但是我无法使用 z-index 让子 div 位于父 div 之上。
这是我的 HTML:
<div class="some-element">
<div class="parent-div">
<div class="child-div">
<p>This should be over the parent</p>
</div>
<h1>Some text lorem ipsum</h1>
</div>
<div class="another-div">
<p>lorem ipsum</p>
</div>
</div>
这是我的 CSS
html, body {
height: 100%;
width: 100%;
}
.some-element {
background-color: blue;
width: 100%;
}
.parent-div {
background-color: red;
height: 100%;
position: relative;
width: 100%;
z-index: 1;
}
.child-div {
background-color: green;
height: 100%;
position: relative;
width: 100%;
z-index: 999;
}
这是一个演示我的问题的 CodePen:https://codepen.io/leofontes/pen/LkgJpo
我认为通过使用 z-index 和 position relative 我可以实现我想要的,但它似乎并没有堆叠在父级之上。知道发生了什么吗?
【问题讨论】:
标签: html css position overlay z-index