I tried different things described here: Is it possible to set the stacking order of pseudo-elements below their parent element? And even though the parent element appeared in the front, when i hover over - it goes in the background. It seems that when i use trasfrom on parent element it creates a new stacking context and everything goes brrrrrrrr. I already thought just to create 3 separate divs with different z-indexes and translate them, when i hover over, but is there nice a way to do the this effect with pseudo elements?
Here is a basic example illustrating the issue:
.card_container {
width: 33.333%;
padding: 1rem;
}
.card {
display: block;
height: 100%;
text-align: center;
background-color: #f18e9b;
position: relative;
will-change: transform;
}
.card::before {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
background-color: #e84a5f;
}
.card::after {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -2;
background-color: #cc1a32;
}
.card:hover {
-webkit-transform: translate(-5px, 0);
transform: translate(-5px, 0);
}
.card:hover:before {
-webkit-transform: translate(5px, 0);
transform: translate(5px, 0);
}
.card:hover:after {
-webkit-transform: translate(10px, 0);
transform: translate(10px, 0);
}
.content {
padding: 4rem 1rem;
}
.title {
font-size: 1.25rem;
background-color: gray;
border-radius: 3px;
padding: 0.5rem;
}
<div class="card_container">
<div class="card">
<div class="content">
<div class="title">Title</div>
<div class="subtitle">Subitle</div>
<div class="text">Random random random text</div>
</div>
</div>
</div>
If you want to see the version with sass go here