Crimson-Med
Crimson-Med

Reputation: 221

Dropdown Menu covered by div

Hello I want to add a dropdown menu to my top navigation bar. But for some reason it gets hidden by my image slider. I would like the dropdown content to be on top of everything as it should be.

/* Style The Dropdown Button */
.dropbtn {
  cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
  position: relative;
  display: inline-block;
  z-index: 999;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #565656;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
  color: white;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
  background-color: #f1f1f1
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
  display: block;
}
<div id="header">
  <ul>
    <li>
      <a class="a-no-hover" href="index.html">
        <img src="images/miniLogo.png" />
      </a>
    </li>
    <li><a class="active" href="index.html">HOME</a>
    </li>
    <div class="dropdown">
      <li class="dropbtn"><a href="product.html">PRODUCTS</a>
      </li>
      <div class="dropdown-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </div>
    <li><a href="order.php">ORDER</a>
    </li>
    <li><a href="about.html">ABOUT US</a>
    </li>
    <li><a href="contact.html">CONTACT US</a>
    </li>
  </ul>
</div>
<div id="section1">
  <img id="img" src="images/bg.jpg" />
</div>

Upvotes: 1

Views: 3884

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167172

You are giving z-index to the header menu, that's fine. But the content is what is the problem. So, try giving z-index to the .dropdown-content:

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #565656;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1000; /* One more than the header. */
}

Update

#header ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  /* overflow: hidden; Remove this. */
  text-align: center;
  vertical-align: middle;
}

Preview

enter image description here

Output: http://jsbin.com/lorebubizi/1

Upvotes: 4

Related Questions