I have an element that has a ::before
pseudo element as background.
But as you can see the pseudo element is covering my text.
.wrapper {
background-color: salmon;
padding: 20px;
}
.tag {
position: relative;
display: inline-block;
}
.tag::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: scaleX(1.2) translateY(50%);
background-image: radial-gradient(closest-side, steelblue 99%, transparent 100%);
}
<div class="wrapper">
<span class="tag">Lorum ipsum</span>
</div>
I wish I can target the text node by
.tag:text {
z-index: 1;
}
But it's not possible.
I tried to give the pseudo element z-index: -1;
but it's covered by anything that has a background such as .wrapper
, since all their backgrounds has default z-index
of 0
.
.wrapper {
background-color: salmon;
padding: 20px;
}
.tag {
position: relative;
display: inline-block;
}
.tag::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: scaleX(1.2) translateY(50%);
background-image: radial-gradient(closest-side, steelblue 99%, transparent 100%);
z-index: -1;
}
<div class="wrapper">
<span class="tag">Lorum ipsum</span>
</div>
What I want to achieve:
How can I achieve it without modifying the html structure?