z-index doesn't work with its ::before
/::after
element. Here I'm sharing code below.
.or {
border: 2px solid #8fc300;
border-radius: 5px;
color: #333;
font-size: 17px;
font-weight: 600;
height: 34px;
line-height: 26px;
text-align: center;
width: 34px;
margin-top: 64px;
margin-left: 20px;
margin-right: 20px;
background: #fff;
/*For z-index - keep the green area on top*/
position: relative;
z-index: 11;
}
.or::after {
background: red;
content: "";
display: block;
height: 116px;
margin-left: 15px;
margin-top: -68px;
width: 4px;
/*For z-index - keep the green area on top*/
position: relative;
z-index: 9;
}
<div class="or"></div>
You can remove z-index
from parent element and use negative z-index: -1
on pseudo element. If you want only green line on red line you need to remove white background from parent also DEMO
.or {
border: 2px solid #8fc300;
border-radius: 5px;
color: #333;
font-size: 17px;
font-weight: 600;
height: 34px;
line-height: 26px;
text-align: center;
width: 34px;
margin-top: 64px;
margin-left: 20px;
margin-right: 20px;
background: #fff;
/*For z-index - keep the green area on top*/
position: relative;
}
.or::after {
background: red;
content: "";
display: block;
height: 116px;
margin-left: 15px;
margin-top: -68px;
width: 4px;
/*For z-index - keep the green area on top*/
position: absolute;
z-index: -1;
}
<div class="or"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With