I have an element that contains another element, and due to other parts in the code it would be very hard to disconnect the two elements without breaking things. I have an unrelated element that the child needs to appear above, but the parent is supposed to appear below.
the code below is a recreation of what my attempts and chatgpt questions got me to, the unrelated element still appears above both the parent and the child.
.parent {
position: relative;
background-color: #ccc;
height: 100px;
width: 100px;
z-index: 1;
}
.child {
background-color: #f00;
height: 50px;
width: 50px;
z-index: 3;
}
.unrelated {
position: absolute;
top: 25px;
left: 25px;
background-color: #00f;
height: 25px;
width: 50px;
z-index: 2;
}
<div class="parent">
<div class="child">
Child element
</div>
</div>
<div class="unrelated">
Unrelated element
</div>
is there any way to make the unrelated element appear between them?