Search code examples
htmlcssasp.netnavbardropdown

Nav drop down showing above navbar on hover


drop down showing above parent navigation bar i want to show the drop down below my navigation bar i am using asp.net site master page page link http://eforms.hopto.org/Management/

i just copy the code from w3shools https://www.w3schools.com/howto/howto_css_dropdown_navbar.asp and past to my code and still not working using chrome or Opera but it working with microsoft Edge browser i am using site master page and asp.net

<style>
body {
  font-family: Arial, Helvetica, sans-serif;
}

.navbar {
  overflow: hidden;
  background-color: #333;
}

.navbar a {
  float: left;
  font-size: 16px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

.dropdown {
  float: left;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 16px;  
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  margin: 0;
}

.navbar a:hover, .dropdown:hover .dropbtn {
  background-color: red;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content a {
  float: none;
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.dropdown-content a:hover {
  background-color: #ddd;
}

.dropdown:hover .dropdown-content {
  display: block;
}
</style>

Solution

  • Move it down with top... just add the top here:

    .dropdown-content {
        top: 45px;
    }
    

    OR, add the dropdown-content inside the dropbtn - now they are not inside, but right after - eg:

    <div class="dropdown">
        <button class="dropbtn">
            <i class="fa fa-caret-down"></i>
        </button>
    
        <div class="dropdown-content">
        </div>        
     </div>