I have some html that includes some buttons wrapped in a div class.
.addshade {
left: 0;
width: 100%;
height: 100%;
z-index: 100000;
background: rgba(0, 0, 0, 0.75);
display: block;
}
.cbutton {
cursor: pointer;
display: inline-block;
font-family: Roboto;
font-weight: 700;
font-size: 16px;
border-radius: 5px;
padding: 5px 6px;
min-width: 90px;
text-decoration: none;
-webkit-font-smoothing: antialiased;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
z-index: -1000;
}
<div class="addshade">
<p class="description"></p>
<div class="options">
<a class="buy cbutton whiteonpurple" target="_blank" href="http://www.apple.com/shop/buy-watch/apple-watch">Buy</a>
<a class="hint cbutton whiteonblack" target="_blank">Hint</a>
</div>
<div class="info" style="display: none;">
<div class="bar"></div>
<div class="rehints" id="rehint_55cd0ef28ead0e883c8b4567" style="visibility: hidden;">10 REHINTS</div>
<div class="hinter" style="visibility: hidden;">
<div class="picture monophoto">
<div class="text" style="font-size: 37px; margin-top: 4.375px;">SO</div>
<div class="img" style="background-image: url(http://graph.facebook.com/filler/picture?type=large);" onclick="location.href='/user/filler';"></div>
</div>
<div class="content">
<div class="one">Hinted by:</div>
<div class="two"><a href="/user/sean12oshea">Sean O'Shea</a>
</div>
</div>
</div>
<div class="partnertext">Partnered Hint</div>
<div style="clear:both;"></div>
</div>
</div>
Even with the z-index the buttons are showing in front of the shading that I want:
However, the buttons are in front and clickable. How do I get the desired behavior?
z-index
only works on positioned elements (position:absolute, position:relative, or position:fixed).
Therefore add position:relative;
to .cbutton
.addshade {
left: 0;
width: 100%;
height: 100%;
z-index: 100000;
background: rgba(0, 0, 0, 0.75);
display: block;
}
.cbutton {
cursor: pointer;
display: inline-block;
font-family: Roboto;
font-weight: 700;
font-size: 16px;
border-radius: 5px;
padding: 5px 6px;
min-width: 90px;
text-decoration: none;
-webkit-font-smoothing: antialiased;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
z-index: -1000;
position: relative;
}
<div class="addshade">
<p class="description"></p>
<div class="options">
<a class="buy cbutton whiteonpurple" target="_blank" href="http://www.apple.com/shop/buy-watch/apple-watch">Buy</a>
<a class="hint cbutton whiteonblack" target="_blank">Hint</a>
</div>
<div class="info" style="display: none;">
<div class="bar"></div>
<div class="rehints" id="rehint_55cd0ef28ead0e883c8b4567" style="visibility: hidden;">10 REHINTS</div>
<div class="hinter" style="visibility: hidden;">
<div class="picture monophoto">
<div class="text" style="font-size: 37px; margin-top: 4.375px;">SO</div>
<div class="img" style="background-image: url(http://graph.facebook.com/filler/picture?type=large);" onclick="location.href='/user/filler';"></div>
</div>
<div class="content">
<div class="one">Hinted by:</div>
<div class="two"><a href="/user/sean12oshea">Sean O'Shea</a>
</div>
</div>
</div>
<div class="partnertext">Partnered Hint</div>
<div style="clear:both;"></div>
</div>
</div>
See the answer here. It says,
z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).
Thus add
z-index: -1000;
position: relative;
to .cbutton
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