简体   繁体   English

下拉菜单显示不正确

[英]Dropdown menu not showing correctly

So I've tried to create a drop-down menu according to the W3Schools HTML and CSS guide. 因此,我尝试根据W3Schools HTML和CSS指南创建一个下拉菜单。

Dropdown inside Navbar 导航栏内的下拉菜单

This is my Code, 这是我的密码

 ul { position: absolute; top: 200px; list-style-type: none; margin: 0; padding: 0; overflow: hidden; background: rgba(0, 0, 0, 0.6); width: 100%; } li { float: left; font-family: TW Cen MT Regular; font-size: 156.25%; height: 70px; line-height: 70px; width: 12%; } li a, .dropbtn { display: block; color: white; text-align: center; text-decoration: none; } li a:hover, .dropdownmenu:hover .dropbtn { background: black; } li.dropdownmenu { display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: red; width: 12%; } .dropdown-content a { color: white; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .dropdown-content a:hover { color: #00fff6; } .dropdownmenu:hover .dropdown-content { display: block; } 
 <ul> <li id="About"><a href="About.html">ABOUT</a></li> <li id="Ongoing"><a href="NOTSET.html">NOTSET</a></li> <li id="Completed" class="dropdownmenu"> <a href="javascript:void(0)" class="dropbtn">COMPLETED</a> <div class="dropdown-content"> <a href="The Crispy.html">"The Crispy"</a> <a href="New Project.html">New Project</a> </div> </li> <li id="BuildLog"><a href="BuildLog.html">BUILD LOGS</a></li> <li id="Contact"><a href="Contact.html">CONTACT</a></li> </ul> 

and it looks like this currently, the problem is as you see the drop-down content doesn't display correctly when im hovering. 并且当前看起来像这样,问题是因为您看到悬停时下拉内容无法正确显示。 you can see the very little red on the bottom of the completed section. 您会在完成部分的底部看到很少的红色。

website 网站

We tell many people W3School is bad to learn. 我们告诉很多人W3School学习不好。 This is the best example. 这是最好的例子。 There are many good snippets you can find in Google . 您可以在Google找到许多不错的摘要。

To fix your issue, 为了解决您的问题,

Remove overflow: hidden from ul style 消除overflow: hidden ul样式overflow: hidden

 ul { position: absolute; top: 200px; list-style-type: none; margin: 0; padding: 0; /*overflow: hidden*/ background: rgba(0, 0, 0, 0.6); width: 100%; } li { float: left; font-family: TW Cen MT Regular; font-size: 156.25%; height: 70px; line-height: 70px; width: 12%; } li a, .dropbtn { display: block; color: white; text-align: center; text-decoration: none; } li a:hover, .dropdownmenu:hover .dropbtn { background: black; } li.dropdownmenu { display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: red; width: 12%; } .dropdown-content a { color: white; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .dropdown-content a:hover { color: #00fff6; } .dropdownmenu:hover .dropdown-content { display: block; } 
 <ul> <li id="About"><a href="About.html">ABOUT</a></li> <li id="Ongoing"><a href="NOTSET.html">NOTSET</a></li> <li id="Completed" class="dropdownmenu"> <a href="javascript:void(0)" class="dropbtn">COMPLETED</a> <div class="dropdown-content"> <a href="The Crispy.html">"The Crispy"</a> <a href="New Project.html">New Project</a> </div> </li> <li id="BuildLog"><a href="BuildLog.html">BUILD LOGS</a></li> <li id="Contact"><a href="Contact.html">CONTACT</a></li> </ul> 

Just remove overflow hidden from ul css and it will works fine. 只需删除ul css中隐藏的溢出,它将正常工作。

ul {
  position: absolute;
  top: 200px;
  list-style-type: none;
  margin: 0;
  padding: 0;
  /*overflow: hidden*/
  background: rgba(0, 0, 0, 0.6);
  width: 100%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM