JSFiddle - React, Tailwind, and code Playground
HTML
<div id="flex-container">
<div id="flex-item-1" class="flex-item">
flex item 1
<div class="div-under-item-1">div under item 1</div>
</div>
<div id="flex-item-2" class="flex-item">
flex item 2
</div>
</div>
<input type="button" onclick="removeZIndex();" value="remove z-index from flex container">
<input type="button" onclick="addZIndex();" value="add z-index to flex item 1">
CSS
#flex-container {
position: relative;
z-index: 1;
display: flex;
justify-content: space-around;
width: 600px;
height: 250px;
background-color: lightgray;
margin-bottom: 40px;
}
.flex-item {
width: 200px;
height: 200px;
}
#flex-item-1 {
position: relative;
background-color: aqua;
}
#flex-item-2 {
background-color: lightgreen;
}
.div-under-item-1 {
position: absolute;
z-index: -1;
width: 200px;
height: 150px;
left: 150px;
bottom: -70px;
background-color: red;
padding: 0 30%;
box-sizing: border-box;
text-align: center;
}
JavaScript
function addZIndex() {
document.getElementById("flex-item-1").style.zIndex="1";
}
function removeZIndex() {
document.getElementById("flex-container").style.zIndex="auto";
}