You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

导航栏菜单链接无法点击求助(PC端导航功能正常)

Hey there, let's walk through fixing your navigation problem. I've looked at your code and spotted a few key issues that are causing links to fail on mobile, even though everything works on desktop.

1. First: Clean Up Invalid HTML Structure

Your code has a few extra closing </div> tags at the end—these can mess up the DOM layout, especially on mobile where responsive behavior depends on proper nesting. Here's the cleaned-up version of your header code:

<header class="site-navbar py-4 js-sticky-header site-navbar-target" role="banner">
  <div class="mr-auto">
    <nav class="site-navigation position-relative text-right" role="navigation">
      <ul class="site-menu main-menu js-clone-nav mr-auto d-none d-lg-block">
        <li class="active">
          <a href="index.html" class="nav-link text-left">Home</a>
        </li>
        <li class="has-children">
          <a href="about.html" class="nav-link text-left">About Us</a>
          <ul class="dropdown">
            <li><a href="teachers.html">Our Teachers</a></li>
            <li><a href="about.html">Our School</a></li>
          </ul>
        </li>
        <li>
          <a href="admissions.html" class="nav-link text-left">Admissions</a>
        </li>
        <li>
          <a href="courses.html" class="nav-link text-left">Courses</a>
        </li>
        <li>
          <a href="contact.html" class="nav-link text-left">Contact</a>
        </li>
      </ul>
    </nav>
  </div>
  <div class="ml-auto">
    <div class="social-wrap">
      <a href="#"><span class="icon-facebook"></span></a>
      <a href="#"><span class="icon-twitter"></span></a>
      <a href="#"><span class="icon-linkedin"></span></a>
      <a href="#" class="d-inline-block d-lg-none site-menu-toggle js-menu-toggle text-black"><span class="icon-menu h3"></span></a>
    </div>
  </div>
</header>

2. Fix Mobile Menu Toggle & Dropdown Interactions

The biggest issue here is missing JavaScript to handle mobile menu behavior. Your classes like js-menu-toggle and js-clone-nav suggest your theme expects some JS to make mobile navigation work, but it's not set up. Add this vanilla JS snippet right before your closing </body> tag:

document.addEventListener('DOMContentLoaded', function() {
  // Toggle mobile menu when the hamburger icon is clicked
  const menuToggle = document.querySelector('.js-menu-toggle');
  const mainMenu = document.querySelector('.main-menu');

  menuToggle.addEventListener('click', function(e) {
    e.preventDefault();
    mainMenu.classList.toggle('d-block');
    mainMenu.classList.toggle('d-lg-none');
  });

  // Handle dropdown menus on mobile (toggle instead of immediate redirect)
  const dropdownParents = document.querySelectorAll('.has-children');
  
  dropdownParents.forEach(parent => {
    const parentLink = parent.querySelector('a:first-child');
    parentLink.addEventListener('click', function(e) {
      const dropdown = parent.querySelector('.dropdown');
      // Only override the link behavior on mobile screens
      if (window.innerWidth < 992) {
        e.preventDefault();
        dropdown.classList.toggle('d-block');
      }
    });
  });
});

Make sure your HTML files are in the right place relative to each other:

  • If index.html, about.html, etc., are all in your root folder, your current href values are correct
  • If you have a subfolder (like pages/about.html), update the links to match that structure (e.g., href="pages/about.html")

4. Add CSS for Mobile Dropdown Styling

To make the mobile dropdowns look and behave properly, add this CSS to your stylesheet:

@media (max-width: 991px) {
  .main-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    width: 100%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1rem;
    z-index: 100;
  }

  .main-menu.d-block {
    display: block !important;
  }

  .has-children .dropdown {
    display: none;
    padding-left: 1.5rem;
    margin-top: 0.5rem;
  }

  .has-children .dropdown.d-block {
    display: block !important;
  }
}

After applying these changes, your mobile navigation links should work just like the desktop version. Test it on a small screen or using your browser's dev tools mobile emulator to confirm!

内容的提问来源于stack exchange,提问作者Heman Kadariya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 11:37:56