当我尝试选择任何元素时,下拉菜单隐藏。?(CSS)

时间:2017-02-10 11:17:28

标签: html css html5 css3

嗨,我知道这已被问过几次,但我无法在代码中得到错误。当我将鼠标悬停在 APPLIANCES 上时,我的下拉区块会显示perfecteley,但只要我尝试选择任何元素 DROP DOWN DISAPPER .Below就是我的代码: -

HTML: -

    #nav_wrapper
    {
        
        
        position: relative;
        top: 70px;
        left: 100px;
        
    }
    #nav_wrapper ul{
     list-style-type: none;   
     }
     
     #nav_wrapper ul li{
         outline: 1px solid white;
         width: 160px;
         text-align: center;
         position: relative;
         float: left;
         background: black;
         z-index: 1000;
         
     }
     #nav_wrapper ul li a{
         text-decoration: none;
         display: inline-block;
         height: 25px;
         width: 160px;
         padding-top: 5px;
         color: #DAA520;
         font-family: cursive;
         
     }
    
     
     
     #nav_wrapper ul ul.one
     {
         display: none;
     }
     #nav_wrapper ul li a:hover {
          color: wheat; 
          
     }
     
     
     #nav_wrapper ul li a:hover + ul.one {
         display: inline-block;
         height: 25px;
         
     }
<div id="nav_wrapper">
                       <ul>
                           <li><a href="#">ELECTRONICS</a>
                               
                           </li> 
                           <li><a href="#">APPLIANCES</a>
                           <ul class="one">
                                  <li><a href="#">TV</a></li>
                                  <li><a href="#">WASHING MACHINE</a></li>
                             </ul>
                               </li>
                           <li><a href="#">MEN</a></li>
                           <li><a href="#">WOMEN</a></li>
                           <li><a href="#">BABY&KIDS</a></li>
                           <li><a href="#">HOME&FURNITURE</a></li>
                           <li><a href="#">BOOKS&MORE</a></li>
                           
                       </ul>
                 
               </div>
    


     

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:2)

下面是代码..刚刚更改了悬停css .. 我的代码正在工作,看图像..

#nav_wrapper ul li:hover > ul.one {
  display: inline-block;
  height: 25px;
}

&#13;
&#13;
#nav_wrapper {
  position: relative;
  top: 70px;
  left: 100px;
}
#nav_wrapper ul {
  list-style-type: none;
}
#nav_wrapper ul li {
  outline: 1px solid white;
  width: 160px;
  text-align: center;
  position: relative;
  float: left;
  background: black;
  z-index: 1000;
}
#nav_wrapper ul li a {
  text-decoration: none;
  display: inline-block;
  height: 25px;
  width: 160px;
  padding-top: 5px;
  color: #DAA520;
  font-family: cursive;
}
#nav_wrapper ul ul.one {
  display: none;
}
#nav_wrapper ul li a:hover {
  color: wheat;
}
#nav_wrapper ul li:hover > ul.one {
  display: inline-block;
  height: 25px;
}
&#13;
<div id="nav_wrapper">
  <ul>
    <li><a href="#">ELECTRONICS</a>

    </li>
    <li><a href="#">APPLIANCES</a>
      <ul class="one">
        <li><a href="#">TV</a>
        </li>
        <li><a href="#">WASHING MACHINE</a>
        </li>
      </ul>
    </li>
    <li><a href="#">MEN</a>
    </li>
    <li><a href="#">WOMEN</a>
    </li>
    <li><a href="#">BABY&KIDS</a>
    </li>
    <li><a href="#">HOME&FURNITURE</a>
    </li>
    <li><a href="#">BOOKS&MORE</a>
    </li>

  </ul>

</div>
&#13;
&#13;
&#13;

enter image description here

答案 1 :(得分:0)

<!DOCTYPE html>
<html>
<head>

    <title></title>
<style>
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
}

li a, .dropbtn {
    display: inline-block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

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

li.dropdown {
    display: inline-block;
}

.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 {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}

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

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


</head>
<body>




<div id="nav_wrapper">
 <ul>
  <li><a href="#home">ELECTRONICS</a></li>
  <li><a href="#news">News</a></li>
  <li class="dropdown">
    <a href="#" class="dropbtn">APPLIANCES</a>
    <div class="dropdown-content">
      <a href="#">TV</a>
      <a href="#">WASHING MACHINE</a>
    </div>
    <li><a href="#home">MEN</a></li>
    <li><a href="#news">WOMEN</a></li>
    <li><a href="#">BABY&KIDS</a></li>
    <li><a href="#">HOME&FURNITURE</a></li>
     <li><a href="#">BOOKS&MORE</a></li>
  </li>
</ul>
</div>
</body>
</html>