Bootstrap 导航栏在移动设备上使用一次后就消失了

Bootstrap Navbar disappears on mobile after using it once

我的 Bootstrap 导航栏有问题。当我在移动设备上使用导航栏时,它会在切换后消失。

这是我的导航栏代码:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>

<!--Navbar-->
<nav class="navbar navbar-expand-lg navbar-light fixed-top" id="navbarSupportedContent">
  <a class="navbar-brand" href="#">Ewert Loitz Personenberförderung</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="true" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Startseite <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#ÜberUns">Über uns</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#Fuhrpark">Fuhrpark</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Kontakt</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Karriere</a>
      </li>
    </ul>
  </div>
</nav>

外层<nav class="navbar navbar-expand-lg navbar-light fixed-top" id="navbarSupportedContent">和内层<div class="collapse navbar-collapse" id="navbarSupportedContent">共享同一个idnavbarSupportedContent。 (实际上,HTML中不允许有相同id的元素。)

ID 为 navbarSupportedContent 的所有元素都根据 data-toggle 折叠起来 和 <button> 中定义的 <button> 属性,包括 nav#navbarSupportedContent,因此整个导航栏消失了。

您需要做的就是从 <nav> 元素中删除 id="navbarSupportedContent"

参考:https://getbootstrap.com/docs/4.6/components/navbar/#supported-content