ale*_*exP 5 html css z-index pseudo-element
如果我将鼠标悬停在 DIV 上,我希望在我的 DIV 容器下放置一个弯曲的阴影。不幸的是,阴影在我的盒子上方而不是下方。有什么建议?
这是我的 CSS:
.appointment {
position: relative;
z-index: 1000;
padding: 5px;
border: 1px solid #BBBBBB;
cursor: pointer;
transition: all 0.5s;
background: #FFFFFF;
}
.appointment:hover {
transform: scale(1.1);
}
.appointment:hover:after {
content:'';
position: absolute;
z-index: -1;
top: 20px;
width: 100px;
height: 45px;
background: #000000;
transform: rotate(-5deg);
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="appointment">
<div class="desc">
<div class="app-date">07.10.2014</div>
<div class="app-location">Bamberg, Bayern</div>
</div>
</div>
<div class="appointment" >
<div class="desc">
<div class="app-date">08.10.2014</div>
<div class="app-location">Hamburg, Hamburg</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
它应该是这样的:

根据这个答案:z-index 通过转换取消,您需要更改标记。
<div class="appointment-wrapper">
<div class="appointment">
<div class="desc">
<div class="app-date">07.10.2014</div>
<div class="app-location">Bamberg, Bayern</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
然后在约会包装器上使用transform:scale(1.1)。
.appointment-wrapper:hover
{
transform: scale(1.1);
}
Run Code Online (Sandbox Code Playgroud)
这种方式.appointment和它的伪元素共享相同的堆叠上下文。
编辑:请注意,伪元素也会被转换。