Browser: Chrome Version 71.0.3578.98 (64-bit)
I'm trying to create an easy way to set an opaque image on a background without editing the image in Photoshop, but when I use an absolutely positioned ::before pseudo-class, inside of a position: relative; parent, it blocks the inputs within the section preventing anyone from using them; although the background image displays behind the parents children's. When I noticed this, I tried setting the ::before to z-index: 0; and the parent to z-index: 1; and it didn't solve the problem. However, when I set the parent to z-index: 0; and the pseudo-class to z-index: -1; it works perfectly.
Why does it have to be z-index 0 and -1 instead of the former?
/* z-index: -1 commented out in .box:before */
.box {
position: relative;
z-index: 0;
text-align: center;
padding: 20px;
}
.box:before {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: #dddddd;
//z-index: -1;
opacity: .5;
}
<div class="box">
<b>Click Input</b><br /><br />
<input type="text" class="text">
</div>