I'm trying to create a dropdown in my fixed navbar. When I click the open button, I want the overlay to cover everything except the dropdown content.
Even after setting the z-index of my dropdown content to 10000, it still didn't work.
$("#dropDownButton").click(function () {
$(".dropdown-content").toggleClass("show");
if ($(".dropdown-content").hasClass("show")) {
$(".overlayT").fadeIn(500);
} else {
$(".overlayT").fadeOut(500);
}
});
body {
font-family: "Lato", sans-serif;
}
.overlayT {
position: fixed;
top: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 2;
display: none;
height: 100%;
width: 100%;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
min-width: 200px;
border-radius: 5px;
padding-top: 2rem;
z-index: 10000;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.show {
display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="overlayT">
</div>
<div style="width: 100%; background-color: white; height:100px; border-style: solid; position: fixed; z-index: 1"
id="dropDownButton">
<span style="font-size:30px;cursor:pointer; float:left; margin-left: 3rem">☰ open
<div class="dropdown-content">
<a href="#">Home</a>
<a href="#">Account</a>
<a href="#">Sign Out</a>
</div>
</span>
</div>
Is there a way for my overlay not to cover the dropdown content while keeping the navbar fixed? Your help is greatly appreciated. Thank you!