【发布时间】:2019-12-04 09:38:19
【问题描述】:
我正在尝试在横幅图像上覆盖一些面包屑。我没有使用绝对定位或类似的解决方案,而是使用负边距。
由于某种原因,横幅文本的边缘覆盖了面包屑,这意味着它们无法被点击或选择。
我的假设是这是一个简单的 z-index 问题,但我无法让 z-index 工作。无论我把它放在哪里或我将它设置为什么值,问题都仍然存在。据我所知,它只发生在display: flex。
这是问题的简化版本:
https://codepen.io/anon/pen/jgMGYj
.small-text
{
margin-bottom: -20px;
}
.small-text span
{
background-color: orange;
}
.big-container
{
display: flex;
align-items: center;
background-color: purple;
}
.big-text
{
display: flex;
flex-direction: column;
align-items: center;
}
.big-text span
{
margin-top: 50px;
background-color: lime;
}
<div class="small-text">
<span>I want to select/highlight this.</span>
</div>
<div class="big-container">
<div class="big-text">
<span>But this element's margin is covering it up.</span>
</div>
</div>
这是什么原因?是否有一些我不理解的 z-index 规则?它是一个弹性错误吗?是否可以在不删除display: flex的情况下修复它?
【问题讨论】: