响应式导航 - Flexbox下拉列表导致溢出

时间:2018-02-27 00:47:44

标签: javascript html css

目前正在做一个快速的网站。得到了导航样式并且工作正常,但是我将下拉列表作为导航项目实现了。这导致了我似乎无法解决的三个问题:

  1. 在导航切换中,内容相互重叠。
  2. 在导航切换中,导航会让您滚动,即使在那里也是如此 是悬浮在桌面屏幕上的下拉菜单的空间。
  3. 在桌面屏幕上,导航项会导致使用滚动条在标题内发生删除。
  4. 一直坚持这一点,我们将不胜感激。

    
    
    function NavToggle() {
      var tn = document.getElementById("nav-bar")
      if (tn.style.display === "none") {
        tn.style.display = "block";
      } else {
        tn.style.display = "none";
      }
    }
    
    * {
      box-sizing: border-box;
      font-family: sans-serif;
      margin: 0;
      padding: 0;
    }
    
    html,
    body {
      overflow-y: auto;
    }
    
    ul {
      margin: 0;
      padding: 0;
    }
    
    
    /* Header and Navigation */
    
    header {
      width: 100vw;
      height: auto;
      background-color: #222;
      position: fixed;
      z-index: 1;
      overflow-y: auto;
      max-height: 100vh;
      overflow-x: hidden;
    }
    
    nav {
      display: none;
      z-index: 2;
    }
    
    .title-wrapper {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 50px;
      width: 100vw;
      padding: 0 10px;
    }
    
    
    /* menu base styles */
    
    nav ul {
      list-style-type: none;
    }
    
    nav li {
      height: 50px;
    }
    
    .title-wrapper>a {
      font-size: 16px;
    }
    
    a {
      color: #999;
    }
    
    nav a {
      text-decoration: none;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      height: 100%;
      font-size: 14px;
      padding-left: 10px;
    }
    
    nav a:hover {
      color: #fff;
    }
    
    
    /* Menu Toggle Styling */
    
    .menu-toggle {
      font-size: 26px;
      color: #fff;
      cursor: pointer;
      padding: 0 15px 0 10px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
    .menu-toggle-button {
      padding: inherit;
    }
    
    @media screen and (min-width: 930px) {
      nav ul {
        display: flex;
      }
      /* Header Content */
      .header-container {
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .menu-toggle {
        display: none;
      }
      .header-wrapper {
        max-width: 1200px;
        width: 100%;
        display: flex;
        justify-content: center;
        padding: 0 20px;
      }
      .header-title {
        font-size: 18px;
      }
      #nav-bar {
        width: 70%;
        display: inline-flex;
        justify-content: space-between;
      }
      a {
        padding: 0 1rem;
      }
      .nav-dropdown {
        position: relative;
      }
      .nav-dropdown-menu {
        display: none;
        position: absolute;
        z-index: 2;
      }
      .nav-dropdown:hover>.nav-dropdown-menu {
        display: block;
      }
    }
    
    <body>
      <header class="nav-wrapper header-container">
        <div class="header-wrapper">
          <div class="title-wrapper">
            <a>Chemical Finger Print Analysis</a>
            <div class="menu-toggle">
              <span id="menu-toggle-button" onclick="NavToggle()">&#9776;</span>
            </div>
          </div>
          <nav id="nav-bar">
            <ul>
              <li><a href="#">Home</a></li>
              <li><a href="#">About</a></li>
              <li><a href="#">Contact</a></li>
              <li><a href="#">Data</a></li>
              <li><a href="#">Reports</a></li>
            </ul>
            <ul>
              <li class="nav-dropdown"><a href="#" class="a-tag header-a">Account</a>
                <ul class="nav-dropdown-menu">
                  <li><a href="#">Account</a></li>
                  <li><a href="#">Order History</a></li>
                  <li><a href="#">Wishlist</a></li>
                </ul>
    
              </li>
              <li><a href="#">Login</a></li>
            </ul>
          </nav>
        </div>
      </header>
    
    
    
    
    
    </body>
    &#13;
    &#13;
    &#13;

0 个答案:

没有答案