Dropmenu问题不显示与HTML和CSS

时间:2020-02-05 15:12:50

标签: html css

ul#menu li ,ul.sub-menu li { list-style-type: none; float:left; } 
ul#menu li a ,ul.sub-menu li a  
{ display: inline-block; width: 150px; height: 40px; text-decoration: none; line-height: 40px; text-align: center; color:rgb(235, 139, 13); background-color:black; border-radius: 20px; } 
 ul#menu li a:hover ,ul.sub-menu li a:hover { background-color: crimson; font-weight: bold; color:white; display: block; border-radius: 20px;
}

ul#menu li { position: relative;

} ul#menu li ul.sub-menu { display:none; position: absolute; top: 30px; left: 0px; width: 100px;

} ul#menu li :hover ul.sub-menu { display: block;

}

Dropdown Menu

menu1
menu2
submenu1
submenu2
submenu3
submenu4
     </li>

 </ul>

1 个答案:

答案 0 :(得分:0)

将此ul#menu li :hover ul.sub-menu更改为ul#menu li:hover ul.sub-menu。这是我假设您的HTML可能如下所示的唯一问题。

<ul id="menu">
    <li>
      <a href="#">menu1</a>
    </li>
    <li>
      <a href="#">menu2</a>
      <ul class="sub-menu">
        <li>
          <a href="#">submenu1</a>
          <a href="#">submenu2</a>
          <a href="#">submenu3</a>
          <a href="#">submenu4</a>
        </li>
      </ul>
    </li>
  </ul>