I have 3 divs that only contain a background color and what I want to make is something similar to the google chrome logo.
This is just part of the code, there is more content that comes on top of all this, but this is basically the background for the page.
Right now, green is on top of red which is fine. But yellow is below both red and green and it should be on TOP of green and UNDER red div. Sort of like entangled divs.
Is there a way to put the yellow div on top of green and under red div to make it look more like google chrome logo. Click here to see the image of what i want it to look like. This is the best i can explain lol i know its complex to understand what im doing.
Here's the code (click for codepen)
.container {
position: relative;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.red {
position: absolute;
left: 30%;
width: 100%;
height: 150vh;
transform: rotate(58deg);
background-color: #b71724;
opacity: 1;
transition: all 0.7s ease-in;
}
.green {
position: absolute;
right: 20%;
width: 110%;
height: 150vh;
transform: rotate(-58deg);
background-color: #2c4b2b;
opacity: 1;
transition: all 0.7s ease-in;
}
.yellow {
position: absolute;
top: 58%;
width: 100%;
height: 100vh;
background-color: #d1aa3b;
z-index: -1;
opacity: 1;
transition: all 0.7s ease-in;
}
<div >
<div ></div>
<div ></div>
<div ></div>
</div>
CodePudding user response:
Assign differents z-index :
.red {
z-index : 3;
}
.yellow {
z-index : 2;
}
.green {
z-index : 1;
}
If you put the same z-index for two divs, then their place into the HTML code will determine their position (last in the body in front)
CodePudding user response:
You can use the z-index on the red and green as you used on yellow changing the z-index of yellow to 0 and defining the z-index of green to -1 and the z-index of red to 1.
CodePudding user response:
No. This is possible with something like paper, but z-index is more like a stack of plates. It would be like stacking plates so that the bottom one is also on top of the top one. Not going to happen.
The only way you could try to "cheat" a solution is to copy the bottom element (yellow), raise it all the way to the top, and somehow mask it so that it looks like it's both under red and above green. I'm not sure what you're trying to do in your actual application, but I would recommend just achieving the effect with an image.
But there is no way to make just these three divs work in the way you describe.