I know there are lots and lots of z-indexing questions, but I cannot seem to find the one that answers this. I have an absolute div (black) that goes on top of the free flow text. I need to have another absolute div sticks at the bottom of the black
div, which is already absolute. So, I decided to have a wrapper div with relative positioning, inside the black
, and then add the additional absolute div (yellow) that I wanted. Just so it will be relative to the original div (black). Its kinda hard to explain with text,
.back {
position: absolute;
width: 100px;
height: 100px;
top: 25%;
left: 30%;
background-color: #000;
z-index: 10;
}
.content1 {
position: relative;
width: 150px;
height: 150px;
top: 52%;
left: 50%;
background-color: red;
z-index: 9;
}
.content2 {
z-index: -1;
position: absolute;
width: 125px;
height: 125px;
top: -30%;
left: 0;
background-color: yellow;
}
<div class="back">
<div class="content1">
<div class="content2"></div>
</div>
</div>
<div>
<b>Free Flow Text</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<br><br><br> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<br><br><br> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
My question is why the yellow goes on top of all the divs when its z-index: -1
, shouldn't it be at the bottom?
What if I want to change the ording? Right now, it is black
, red
and the yellow
on top. What if I want, black
, yellow
and then red
or yellow
, black
and then red
?