导航栏不会随着屏幕尺寸大于 md-breakpoint Bootstrap 进行缩放

Navbar doesn't scale with screensize bigger than md-breakpoint Bootstrap

在我当前的项目中,我有一个带有汉堡菜单的导航栏。它正确缩放到 md-breakpoint,但在此断点之后所有元素都向左移动并且切换工作很奇怪。

中等: view on medium 在笔记本电脑 L - 1440px 上: view on larger than medium 这是我现在 header header 的代码,但我似乎无法弄清楚是什么让我的导航栏表现得如此奇怪,因为我没有指定 md 和>MD.

<header>
<div class="container ">
  <nav class="navbar bg-light navbar-light fixed-top ">
    <button class="navbar-toggler align-items-center" type="button" data-toggle="collapse" data-target="#navDropdownMenu" aria-controls="navbarDropdownToggle" aria-expanded="false" aria-label="Toggle navigation">
      <i class="fa fa-bars"></i>
    </button>

    <a class="navbar-brand mx-auto" href="index.html">FORRESTR</a>

    <button class="shoppingCart navbar-toggler" type="button">
      <i class="fa fa-shopping-cart"></i>
    </button>

    <div class="container">
      <div class="collapse navbar-collapse" id="navDropdownMenu">
        <ul class="navbar-nav">
          <a class="nav-item nav-link active" href="index.html">Products</a>
          <a class="nav-item nav-link" href="ourstory.html">Our Story</a>
          <a class="nav-item nav-link" href="partners.html">Partners</a>
          <a class="nav-item nav-link" href="process.html">Process</a>
          <a class="nav-item nav-link" href="contact.html">Contact Us</a>
          <a class="nav-item nav-link" href="faq.html">FAQ</a>
        </ul>
      </div>
    </div>
  </nav>
</div>

有人知道问题出在哪里吗?

已更新

除了将 class .fixed-top 移动到您的容器之外,如果您想要全宽 header,则必须使用 .container-fluid。另外,您必须移除包裹 narvbar-collapse 的容器。否则我也会对断点做出反应。

<header class="container-fluid fixed-top">
    <nav class="navbar  navbar-light">
        <button class="navbar-toggler align-items-center" type="button" data-toggle="collapse" data-target="#navDropdownMenu" aria-controls="navbarDropdownToggle" aria-expanded="false" aria-label="Toggle navigation">
            <i class="fa fa-bars"></i>
        </button>

        <a class="navbar-brand mx-auto" href="index.html">FORRESTR</a>

        <button class="shoppingCart navbar-toggler" type="button">
            <i class="fa fa-shopping-cart"></i>
        </button>

        <div class="collapse navbar-collapse" id="navDropdownMenu">
            <ul class="navbar-nav">
                <a class="nav-item nav-link active" href="index.html">Products</a>
                <a class="nav-item nav-link" href="ourstory.html">Our Story</a>
                <a class="nav-item nav-link" href="partners.html">Partners</a>
                <a class="nav-item nav-link" href="process.html">Process</a>
                <a class="nav-item nav-link" href="contact.html">Contact Us</a>
                <a class="nav-item nav-link" href="faq.html">FAQ</a>
            </ul>
        </div>
    </nav>
</header>

@Periplo 这是将固定顶部 class 从导航栏替换到父容器后的样子。

After added fixed-top to container instead of navbar 不完全是我想要的,因为我想要一个全角导航栏 :)。这是我的 html 代码:

    <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/stylesheet.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <title>Products</title> 
  </head>



  <header>
    <div class="container fixed-top">
      <nav class="navbar bg-light navbar-light ">
        <button class="navbar-toggler align-items-center" type="button" data-toggle="collapse" data-target="#navDropdownMenu" aria-controls="navbarDropdownToggle" aria-expanded="false" aria-label="Toggle navigation">
          <i class="fa fa-bars"></i>
        </button>

        <a class="navbar-brand mx-auto" href="index.html">FORRESTR</a>

        <button class="shoppingCart navbar-toggler" type="button">
          <i class="fa fa-shopping-cart"></i>
        </button>

        <div class="container">
          <div class="collapse navbar-collapse" id="navDropdownMenu">
            <ul class="navbar-nav">
              <a class="nav-item nav-link active" href="index.html">Products</a>
              <a class="nav-item nav-link" href="ourstory.html">Our Story</a>
              <a class="nav-item nav-link" href="partners.html">Partners</a>
              <a class="nav-item nav-link" href="process.html">Process</a>
              <a class="nav-item nav-link" href="contact.html">Contact Us</a>
              <a class="nav-item nav-link" href="faq.html">FAQ</a>
            </ul>
          </div>
        </div>
      </nav>
    </div>
  </header>



  <main>
    <picture>
      <img class="img-fluid headerImg mt-5 mb-5" src="images/jungle.jpg">
    </picture>

    <div class="container">
      <div class="row">
        <div class="col d-flex mb-3 align-items-center">
          <h1 class="m-0 ml-5" style="flex-grow: 1;">Products</h1>
          <button class="navbar-toggler" type="button">
            <i class="fa fa-list"></i>
          </button>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="row m-0">
        <article class="col-6 col-md-3 col-lg-">
          <img class="img-fluid" src="images/jungle.png" alt="jungleImage">
          <h5 class="mt-1">Productname</h5>
          <h6 class="mt-n2 mb-3">€25,00</h6>
        </article>
        <article class="col-6 col-md-3 col-lg-">
          <img class="img-fluid" src="images/jungle.png" alt="jungleImage">
          <h5 class="mt-1">Productname</h5>
          <h6 class="mt-n2 mb-3">€25,00</h6>
        </article>
        <article class="col-6 col-md-3 col-lg-">
          <img class="img-fluid" src="images/jungle.png" alt="jungleImage">
          <h5 class="mt-1">Productname</h5>
          <h6 class="mt-n2 mb-3">€25,00</h6>
        </article>
        <article class="col-6 col-md-3 col-lg-">
          <img class="img-fluid" src="images/jungle.png" alt="jungleImage">
          <h5 class="mt-1">Productname</h5>
          <h6 class="mt-n2 mb-3">€25,00</h6>
        </article>
        <article class="col-6 col-md-3 col-lg-">
          <img class="img-fluid" src="images/jungle.png" alt="jungleImage">
          <h5 class="mt-1">Productname</h5>
          <h6 class="mt-n2 mb-3">€25,00</h6>
        </article>
        <article class="col-6 col-md-3 col-lg-">
          <img class="img-fluid" src="images/jungle.png" alt="jungleImage">
          <h5 class="mt-1">Productname</h5>
          <h6 class="mt-n2 mb-3">€25,00</h6>
        </article>
        <article class="col-6 col-md-3 col-lg-">
          <img class="img-fluid" src="images/jungle.png" alt="jungleImage">
          <h5 class="mt-1">Productname</h5>
          <h6 class="mt-n2 mb-5">€25,00</h6>
        </article>
        <article class="col-6 col-md-3 col-lg-">
          <img class="img-fluid" src="images/jungle.png" alt="jungleImage">
          <h5 class="mt-1">Productname</h5>
          <h6 class="mt-n2 mb-5">€25,00</h6>
        </article>
      </div>
      <div class="mx-3 mb-5">
        <a href="ourstory.html">
          <button type="submit" class="btn btn-primary col-sm-12 col-md-6 d-flex align-items-center justify-content-center mx-auto">Read our story<i class="button fa fa-angle-double-right ml-2"></i></button>
        </a>
      </div>
    </div>

    <script src="js/jquery-3.4.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </main>



  <footer>
    <div class="container">
      <ul class="list-unstyled">
        <div class="row flex-md-row">
          <div class="col-md-6 col-lg-3">
            <li><a class="mx-3" href="#">Terms &amp; Conditions</a></li>
            <li><a class="mx-3" href="#">Privacy Policy</a></li>
            <li><a class="mx-3" href="#">Return Policy</a></li>
          </div>
          <div class="d-sm-block d-md-none" style="height: 10px; background-color: white; width: 100px; visibility: hidden;"></div>
          <div class="col-md-6 col-lg-3">
            <li><a class="mx-3" href="contact.html">Contact Us</a></li>
            <li><a class="mx-3" href="faq.html">FAQ</a></li>
          </div>
        </div>
      </ul>
      <a href="https://www.instagram.com/biancalooijen/">
        <div class="icons mx-3 float-right">
          <img src="images/instagram.svg" alt="instagramIcon">
        </div>
      </a>
      <a href="https://m.facebook.com/bianca.looijen">
        <div class="icons float-right">
          <img src="images/facebook.svg" alt="facebookIcon">
        </div>
      </a>
    </div>
  </footer>
</html>