简体   繁体   English

下拉菜单/子菜单上的问题,hover 不起作用?

[英]Issues on the dropdown menu / Submenu, hover isn't working?

I have an issue with my dropdown menu: it isn't working.我的下拉菜单有问题:它不起作用。 However, my menu IS.但是,我的菜单是。 The links don't work properly either, they take me to the page but not the section.链接也无法正常工作,它们将我带到页面而不是该部分。

If I take out display: none on the dropdown menu CSS it does show my menu, but not as a dropdown.如果我在下拉菜单 CSS 上删除display: none它会显示我的菜单,但不会显示为下拉菜单。 The menu is properly coded and there I guess, but it somehow doesn't display correctly.菜单编码正确,我猜,但不知何故无法正确显示。

<nav>
  <ul class="menu">
    <li class="...">
      <a href="...">...</a>
    </li>
    <li class="item"><a href="...">..</a></li>
    <div class="....">
      <ul>
        <li><a href="...">...</a></li>
        <li><a href="....">..</a></li>
        <li><a href="..">...</a></li>
        <li><a href="...">...</a></li>
      </ul>
    </div>
    <li class="item"><a href="...">...</a></li>
    <li class="item"><a href="...">...</a></li>
    <li class="item"><a href="..">..</a></li>
  </ul>
</nav>

It's semantically not correct to add div inside ul .ul中添加 div 在语义上是不正确的。 Add submenu inside the parent li to which submenu belongs.在子菜单所属的父 li 内添加子菜单。

 nav { width: 100%; flex: 1; } nav ul { display: flex; flex-flow: row wrap; list-style: none; padding-top: 4%; margin: 0; } nav ul li { padding: 1em 4em; } nav ul li a { text-decoration: none; margin-right: auto; color: #000; font-size: 17px; } nav ul li a:hover { border-bottom: 2px solid #724c20; } li.logo { margin-right: auto; }.Submenu { display: none; } nav ul li:hover.Submenu { display: block; background-color: #724c20; position: absolute; margin-top: 15px; margin-left: -15px; } nav ul li:hover.Submenu ul { display: block; margin: 10px; } nav ul li:hover.Submenu ul li { width: 150px; padding: 10px; border-bottom: 1px; background: transparent; border-radius: 0; text-align: center; } nav ul li:hover.Submenu ul li:last-child { border-bottom: none; } nav ul li:hover.Submenu ul li a:hover { color: #d1b9a5; }
 <nav> <ul class="menu"> <li class="logo"> <a href="..."><img src="..." class="logo" alt="..."></a> </li> <li class="item"><a href="...">..</a> <div class="Submenu"> <ul> <li><a href="..">..</a></li> <li><a href="..">..</a></li> <li><a href="..">..</a></li> <li><a href="..">..</a></li> </ul> </div> </li> <li class="item"><a href="...">..</a></li> <li class="item"><a href="...">..</a> <div class="Submenu"> <ul> <li><a href="..">..</a></li> <li><a href="..">..</a></li> <li><a href="..">..</a></li> <li><a href="..">..</a></li> <li><a href="..">..</a></li> </ul> </div> </li> <li class="item"><a href="..">..</a></li> </ul> </nav>

I use javascript to make drop down menues.我使用 javascript 来制作下拉菜单。 Take the dropdown menu display: none;取下拉菜单display: none; . . To show drop down menu you have to do something, like click to an icon.要显示下拉菜单,您必须执行某些操作,例如单击图标。 So you have to import an icon or add a button and use javascript:所以你必须导入一个图标或添加一个按钮并使用 javascript:

<script type="text/javascript">
        $("*here comes your icon's/div's/button's id/class name you want*").click(function(){
          $(".Submenu").toggleClass("active");
        });
    </script>

than you have to write in CSS what hapens when.Submenu will be active:比你必须在 CSS 中写下发生的事情。子菜单将处于活动状态:

.Submenu.active {
display: block;
}

Here an exemple from my last project:这是我上一个项目的一个例子:

<script type="text/javascript">
        $(".menu-toggle-btn").click(function(){
          $(this).toggleClass("fa-times");
          $(".navigation-menu").toggleClass("active");
        });

If you want to when you click on an icon and the menu drops down the icon will change to another you have to write this to your javascript script: $(this).toggleClass("fa-times");如果你想当你点击一个图标并且菜单下拉图标将变为另一个你必须将它写入你的 javascript 脚本: $(this).toggleClass("fa-times"); . . toggleClass("here comes your icons class name ");

If you have any other questions feel free to ask.如果您有任何其他问题,请随时提出。

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

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