I'm trying to overlay some breadcrumbs over a banner image. Rather than use absolute positioning or a similar solution, I'm using a negative margin.
For some reason, the margin of the banner's text is covering up the breadcrumbs, which means that they can't be clicked on or selected.
My assumption was that this was a simple z-index issue, but I can't get z-index to work. No matter where I put it or what values I set it to, the issue persists. From what I can tell, it only happens with display: flex
.
Here's a simplified version of the problem:
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>
What is the reason for this? Is there some z-index rule that I don't understand? Is it a flex bug? Is it possible to fix it without removing display: flex
?