【问题标题】:Bootstrap 5 navbar responsive menu (dropdown part of it)Bootstrap 5 导航栏响应菜单(它的下拉部分)
【发布时间】:2022-10-22 01:15:34
【问题描述】:

更新:我设法让桌面工作。现在只需要整理一下手机。

我遇到的问题是下拉菜单在移动/桌面上似乎无法正常工作。就桌面/移动设备而言,在造型方面它也很好/很好。但问题在于功能。我在下拉项中放入了一些占位符链接(以查看是否会使它们出现),但事实并非如此。

查看我要开始工作的菜单:

<nav id="navbar"class="navbar navbar-expand-lg">
  <div class="container-fluid">
    <img class="navbar-brand" src="[[++url_images]]/logos/logo.jpg" alt="Your image is not loading"></a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarScroll" aria-controls="navbarScroll" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarScroll">
      <ul class="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll" style="--bs-scroll-height: 100px;">
        <li class="nav-item">
          <a class="nav-link active home" aria-current="page" href="https://www.google.com">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link about" href="https://www.google.com">About us</a>
        </li>
        <li class="nav-item">
          <a class="nav-link contact" href="https://www.google.com">Contact</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Link
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarScrollingDropdown">
            <li><a class="dropdown-item" href="https://www.google.com">Action</a></li>
            <li><a class="dropdown-item" href="https://www.google.com">Another action</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="https://www.google.com">Something else here</a></li>
          </ul>
        </li>
      </ul>
      <form class="d-flex" role="search">
        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success" type="submit">Search</button>
      </form>
    </div>
  </div>
</nav>
  • 另外值得注意的是:我可以注意到课程在折叠和折叠和折叠显示之间切换。但它没有显示任何项目。

有人知道为什么菜单不显示吗?这可能是预先存在的 CSS 正在干扰吗? (我已经在有限的范围内检查了这一点,因为这是我的第一个想法。但我无法通过禁用一些明显的项目来显示项目。) 现在我想知道我是否遗漏了什么,或者我应该深入挖掘我的自定义 CSS。

目前也无法再次解决这个问题(但我之前在一个更简单的引导菜单上管理过这个,所以我会弄清楚这个。但如果有人有某种神奇的建议,我愿意接受。)

另见附上我当前编译的 CSS:

/* MODULES ***************************************************************************************/
@import url("https://fonts.googleapis.com/css2?family=Bree+Serif&family=Open+Sans:wght@400;600;700&display=swap");
/* PARTIALS **************************************************************************************/
.heading-xxl {
  font-family: "Bree Serif", serif;
  font-weight: 400;
  font-size: 40px;
  line-height: 48px;
}

.heading-xl {
  font-family: "Bree Serif", serif;
  font-weight: 400;
  font-size: 34px;
  line-height: 38px;
}

.heading-l {
  font-family: "Bree Serif", serif;
  font-weight: 400;
  font-size: 20px;
  line-height: 24px;
}

.heading-m {
  font-family: "Open Sans", sans-serif;
  font-weight: 400;
  font-size: 20px;
  line-height: 24px;
}

.heading-s {
  font-family: "Open Sans", sans-serif;
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
}

.heading-xs {
  font-family: "Open Sans", sans-serif;
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
}

.font-text-l {
  font-family: "Open Sans", sans-serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 24px;
}

.font-text-m {
  font-family: "Open Sans", sans-serif;
  font-weight: 400;
  font-size: 16px;
  line-height: 24px;
}

.font-text-s {
  font-family: "Open Sans", sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 21px;
}

.heading-xxl.color-here {
  color: #07BE54;
}
.heading-xxl.color-here {
  color: #949BFF;
}
.heading-xxl.color-here {
  color: #FF965A;
}
.heading-xxl.color-here {
  color: #25DC71;
}
.heading-xxl.color-here {
  color: #125C30;
}

.heading-xl.color-here {
  color: #07BE54;
}
.heading-xl.color-here {
  color: #949BFF;
}
.heading-xl.color-here {
  color: #FF965A;
}
.heading-xl.color-here {
  color: #25DC71;
}
.heading-xl.color-here {
  color: #125C30;
}

html {
  background-color: #1e4785;
}
@media print, screen and (max-width: 63.99875em) {
  html {
    max-width: 100%;
  }
}

.content {
  max-width: 70%;
}

.gradient-line-transparant {
  background: linear-gradient(to right, rgb(30, 71, 133), rgb(246, 255, 255), rgb(246, 255, 255), rgb(30, 71, 133));
}

.logo {
  max-width: auto;
  max-height: auto;
}
.logo.center {
  display: flex;
  margin-left: auto;
  margin-right: auto;
  height: auto;
  width: 100%;
  padding-top: 28px;
}
.logo.chinook {
  align-self: center;
}

.photo {
  max-width: auto;
  max-height: auto;
}
@media print, screen and (max-width: 63.99875em) {
  .photo {
    max-width: 70%;
    max-height: auto;
  }
}
.photo.left {
  float: left;
  margin-right: 20px;
}
.photo.right {
  float: right;
}

div h1 {
  font-size: 40px;
  color: #1e4785;
  text-align: center;
  margin-top: 0;
}
@media print, screen and (max-width: 63.99875em) {
  div h1 {
    font-size: 0.9em;
    align-self: center;
  }
}
div h2, div h3, div h4, div h5 {
  color: #1e4785;
  text-align: center;
  margin-top: 0;
}
div p {
  width: 100%;
}

p, li, ul, u, i {
  color: #1e4785;
  font-size: 20px;
  margin-left: auto;
  margin-right: auto;
}

a {
  color: #f89830; /*Dutch Orange*/
}

iframe.discord {
  width: 425px;
  height: 500px;
}
@media print, screen and (max-width: 63.99875em) {
  iframe {
    width: 225px;
    height: 300px;
    float: left;
  }
}

.gametracker {
  float: right;
}

li {
  display: inline;
  margin-left: 100px;
  align-items: center;
}

a {
  color: #f89830; /*Dutch Orange*/
}
a:hover {
  color: #f89830;
  opacity: 0.75;
}

/* ---------------------Sticky Nav Styling--------------------- */
/* Style the navbar */
#navbar {
  overflow: hidden;
  padding: 0 0 0 0;
  background-color: #1e4785;
  height: 10vh;
}

.navbar-brand {
  width: 95px;
  height: 95px;
}

.container {
  --bs-gutter-x: 0;
}
.container .menu {
  padding: 0 0 0 0;
}

/* Navbar links */
#navbar a {
  float: left;
  display: block;
  color: #f89830;
  text-align: center;
  text-decoration: none;
  height: 3vh;
}
@media print, screen and (max-width: 63.99875em) {
  #navbar a {
    font-size: 12px;
    margin-top: 17px;
  }
}
#navbar a.home {
  margin-left: 5em;
}
@media print, screen and (max-width: 63.99875em) {
  #navbar a.home {
    margin-left: 1em;
  }
}
#navbar a.about {
  padding-left: 50px;
}
#navbar a.contact {
  padding-left: 50px;
}

/* Page content */
.content {
  padding: 16px;
}

/* The sticky class is added to the navbar with JS when it reaches its scroll position */
.sticky {
  position: fixed;
  height: 5vh;
  width: 100%;
  background-color: #1e4785;
  margin-top: -0.5em;
  z-index: 99999;
}

/* Add some top padding to the page content to prevent sudden quick movement (as the navigation bar gets a new position at the top of the page (position:fixed and top:0) */
.sticky + .content {
  padding-top: 60px;
}

/*header closing tag*/
footer {
  text-align: center;
}
footerli, footer ul, footer u, footer i {
  color: #1e4785;
  font-size: 20px;
  text-align: center;
}
footerh1, footer h2, footer h3, footer h4, footer h5 {
  color: #1e4785;
  text-align: center;
}
footer a, footer a:hover {
  background-color: #1e4785;
  color: #f89830; /*Dutch Orange*/
  text-align: center;
}
footer p.col-md {
  background-color: #1e4785;
  color: #f7ffff;
  font-size: 18px;
  margin-bottom: 0;
}

section {
  align-self: center;
}
section div {
  text-align: center;
}
section div p {
  font-weight: normal;
}

/*---------------Button styling below---------------*/
.button-primary {
  align-items: center;
  appearance: none;
  background-image: radial-gradient(100% 100% at 100% 0, #5adaff 0, #5468ff 100%);
  border: 0;
  border-radius: 6px;
  box-shadow: rgba(45, 35, 66, 0.4) 0 2px 4px, rgba(45, 35, 66, 0.3) 0 7px 13px -3px, rgba(58, 65, 111, 0.5) 0 -3px 0 inset;
  box-sizing: border-box;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-family: "JetBrains Mono", monospace;
  height: 48px;
  justify-content: center;
  line-height: 1;
  list-style: none;
  overflow: hidden;
  padding-left: 16px;
  padding-right: 16px;
  position: relative;
  text-align: left;
  text-decoration: none;
  transition: box-shadow 0.15s, transform 0.15s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  white-space: nowrap;
  will-change: box-shadow, transform;
  font-size: 18px;
}

.button-primary:focus {
  box-shadow: #3c4fe0 0 0 0 1.5px inset, rgba(45, 35, 66, 0.4) 0 2px 4px, rgba(45, 35, 66, 0.3) 0 7px 13px -3px, #3c4fe0 0 -3px 0 inset;
}

.button-primary:hover {
  box-shadow: rgba(45, 35, 66, 0.4) 0 4px 8px, rgba(45, 35, 66, 0.3) 0 7px 13px -3px, #3c4fe0 0 -3px 0 inset;
  transform: translateY(-2px);
}

.button-primary:active {
  box-shadow: #3c4fe0 0 3px 7px inset;
  transform: translateY(2px);
}

body {
  background-color: #1e4785;
}

@media print, screen and (max-width: 63.99875em) {
  .col-md {
    font-size: 35px;
  }
}

/* JAVASCRIPT *************************************************************************************/
/* FOUNDATION IMPORTS*/
html {
  visibility: visible;
}

/*# sourceMappingURL=style.css.map */

【问题讨论】:

    标签: html css menu navbar bootstrap-5


    【解决方案1】:

    自从昨天我发布了关于让它在桌面上运行的更新后,我也设法让它在移动设备上运行。

    我仍然有一些样式问题(我希望菜单位于所有设备上的一个位置,因为我的修补程序涉及固定位置,因此目前尚未发生。)

    但是我遇到的实际问题(它首先不起作用)已通过使用以下代码解决:

      <div class="container-fluid">
        <img class="navbar-brand" src="[[++url_images]]/logos/logo.jpg" alt="Your image is not loading"></a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarScroll" aria-controls="navbarScroll" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarScroll">
          <ul class="navbar-nav navbar-nav-scroll">
            <li class="nav-item">
              <a class="nav-link active home" aria-current="page" href="https://www.google.com">Home</a>
            </li>
            <li class="nav-item">
              <a class="nav-link about" href="https://www.google.com">About us</a>
            </li>
            <li class="nav-item">
              <a class="nav-link contact" href="https://www.google.com">Contact</a>
            </li>
            <!--<li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                Link
              </a>
              <ul class="dropdown-menu" aria-labelledby="navbarScrollingDropdown">
                <li><a class="dropdown-item" href="https://www.google.com">Action</a></li>
                <li><a class="dropdown-item" href="https://www.google.com">Another action</a></li>
                <li><hr class="dropdown-divider"></li>
                <li><a class="dropdown-item" href="https://www.google.com">Something else here</a></li>
              </ul>
            </li>-->
          </ul>
          <form class="d-flex" role="search">
            <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
            <button class="btn btn-outline-success" type="submit">Search</button>
          </form>
        </div>
      </div>
    </nav>```
    
    Compiled CSS (current version which makes it work not counting the styling issues that remain):
    
        /* VENDOR ****************************************************************************************/
    /* MODULES ***************************************************************************************/
    @import url("https://fonts.googleapis.com/css2?family=Bree+Serif&family=Open+Sans:wght@400;600;700&display=swap");
    /* PARTIALS **************************************************************************************/
    .heading-xxl {
      font-family: "Bree Serif", serif;
      font-weight: 400;
      font-size: 40px;
      line-height: 48px;
    }
    
    .heading-xl {
      font-family: "Bree Serif", serif;
      font-weight: 400;
      font-size: 34px;
      line-height: 38px;
    }
    
    .heading-l {
      font-family: "Bree Serif", serif;
      font-weight: 400;
      font-size: 20px;
      line-height: 24px;
    }
    
    .heading-m {
      font-family: "Open Sans", sans-serif;
      font-weight: 400;
      font-size: 20px;
      line-height: 24px;
    }
    
    .heading-s {
      font-family: "Open Sans", sans-serif;
      font-weight: 400;
      font-size: 16px;
      line-height: 24px;
    }
    
    .heading-xs {
      font-family: "Open Sans", sans-serif;
      font-weight: 400;
      font-size: 16px;
      line-height: 24px;
    }
    
    .font-text-l {
      font-family: "Open Sans", sans-serif;
      font-weight: 400;
      font-size: 18px;
      line-height: 24px;
    }
    
    .font-text-m {
      font-family: "Open Sans", sans-serif;
      font-weight: 400;
      font-size: 16px;
      line-height: 24px;
    }
    
    .font-text-s {
      font-family: "Open Sans", sans-serif;
      font-weight: 400;
      font-size: 14px;
      line-height: 21px;
    }
    
    .heading-xxl.color-here {
      color: #07BE54;
    }
    .heading-xxl.color-here {
      color: #949BFF;
    }
    .heading-xxl.color-here {
      color: #FF965A;
    }
    .heading-xxl.color-here {
      color: #25DC71;
    }
    .heading-xxl.color-here {
      color: #125C30;
    }
    
    .heading-xl.color-here {
      color: #07BE54;
    }
    .heading-xl.color-here {
      color: #949BFF;
    }
    .heading-xl.color-here {
      color: #FF965A;
    }
    .heading-xl.color-here {
      color: #25DC71;
    }
    .heading-xl.color-here {
      color: #125C30;
    }
    
    html {
      background-color: #1e4785;
    }
    @media print, screen and (max-width: 63.99875em) {
      html {
        max-width: 100%;
      }
    }
    
    .content {
      max-width: 70%;
    }
    
    .gradient-line-transparant {
      background: linear-gradient(to right, rgb(30, 71, 133), rgb(246, 255, 255), rgb(246, 255, 255), rgb(30, 71, 133));
    }
    
    .logo {
      max-width: auto;
      max-height: auto;
    }
    .logo.center {
      display: flex;
      margin-left: auto;
      margin-right: auto;
      height: auto;
      width: 100%;
    }
    .logo.chinook {
      align-self: center;
    }
    
    .photo {
      max-width: auto;
      max-height: auto;
    }
    @media print, screen and (max-width: 63.99875em) {
      .photo {
        max-width: 70%;
        max-height: auto;
      }
    }
    .photo.left {
      float: left;
      margin-right: 20px;
    }
    .photo.right {
      float: right;
    }
    
    div h1 {
      font-size: 40px;
      color: #1e4785;
      text-align: center;
      margin-top: 0;
    }
    @media print, screen and (max-width: 63.99875em) {
      div h1 {
        font-size: 0.9em;
        align-self: center;
      }
    }
    div h2, div h3, div h4, div h5 {
      color: #1e4785;
      text-align: center;
      margin-top: 0;
    }
    div p {
      width: 100%;
    }
    
    p, li, ul, u, i {
      color: #1e4785;
      font-size: 20px;
      margin-left: auto;
      margin-right: auto;
    }
    
    a {
      color: #f89830; /*Dutch Orange*/
    }
    
    iframe.discord {
      width: 425px;
      height: 500px;
    }
    @media print, screen and (max-width: 63.99875em) {
      iframe {
        width: 225px;
        height: 300px;
        float: left;
      }
    }
    
    .gametracker {
      float: right;
    }
    
    li {
      display: inline-flex;
      margin-left: 100px;
      align-items: center;
    }
    li.nav-item {
      min-width: 100px;
      max-width: 150px;
    }
    
    a {
      color: #f89830; /*Dutch Orange*/
    }
    a:hover {
      opacity: 0.75;
    }
    
    /*<---------------------Sticky Nav Styling--------------------->*/
    /*<---------------------Dropdown menu styling--------------------->*/
    .dropdown-menu.show {
      background-color: #1e4785;
    }
    
    /*<---------------------Style the navbar--------------------->*/
    #navbar {
      padding: 0 0 0 0;
      background-color: #1e4785;
      height: 10vh;
    }
    
    .navbar-brand {
      width: 102px;
      height: 102px;
    }
    @media print, screen and (max-width: 63.99875em) {
      .navbar-brand {
        width: 89px;
        height: 89px;
      }
    }
    
    .navbar-nav-scroll {
      max-height: 100% !important;
    }
    @media print, screen and (max-width: 63.99875em) {
      .navbar-nav-scroll {
        position: fixed;
        margin-left: 8.3em;
        margin-top: -5px;
      }
    }
    
    .container {
      --bs-gutter-x: 0;
    }
    .container .menu {
      padding: 0 0 0 0;
    }
    
    /*<---------------------Navbar links--------------------->*/
    #navbar a, #navbar.a:hover {
      float: left;
      display: block;
      color: #f89830;
      text-align: center;
      margin-left: 0;
      text-decoration: none;
      z-index: 99999;
      background-color: #1e4785;
    }
    @media print, screen and (max-width: 63.99875em) {
      #navbar a, #navbar.a:hover {
        font-size: 12px;
      }
    }
    @media print, screen and (max-width: 63.99875em) {
      #navbar a.home, #navbar.a:hover.home {
        min-width: 100px;
      }
    }
    @media print, screen and (max-width: 63.99875em) {
      #navbar a.about, #navbar.a:hover.about {
        min-width: 100px;
      }
    }
    @media print, screen and (max-width: 63.99875em) {
      #navbar a.contact, #navbar.a:hover.contact {
        min-width: 100px;
      }
    }
    
    /* Page content */
    .content {
      padding: 16px;
    }
    
    /* The sticky class is added to the navbar with JS when it reaches its scroll position */
    .sticky {
      position: fixed;
      height: 5vh;
      width: 100%;
      background-color: #1e4785;
      margin-top: -0.5em;
      z-index: 99999;
    }
    
    /* Add some top padding to the page content to prevent sudden quick movement (as the navigation bar gets a new position at the top of the page (position:fixed and top:0) */
    .sticky + .content {
      padding-top: 60px;
    }
    
    /*header closing tag*/
    footer {
      text-align: center;
    }
    footerli, footer ul, footer u, footer i {
      color: #1e4785;
      font-size: 20px;
      text-align: center;
    }
    footerh1, footer h2, footer h3, footer h4, footer h5 {
      color: #1e4785;
      text-align: center;
    }
    footer a, footer a:hover {
      background-color: #1e4785;
      color: #f89830; /*Dutch Orange*/
      text-align: center;
    }
    footer p.col-md {
      background-color: #1e4785;
      color: #f7ffff;
      font-size: 18px;
      margin-bottom: 0;
    }
    
    section {
      align-self: center;
    }
    section div {
      text-align: center;
    }
    section div p {
      font-weight: normal;
    }
    
    /*---------------Button styling below---------------*/
    .button-primary {
      align-items: center;
      appearance: none;
      background-image: radial-gradient(100% 100% at 100% 0, #5adaff 0, #5468ff 100%);
      border: 0;
      border-radius: 6px;
      box-shadow: rgba(45, 35, 66, 0.4) 0 2px 4px, rgba(45, 35, 66, 0.3) 0 7px 13px -3px, rgba(58, 65, 111, 0.5) 0 -3px 0 inset;
      box-sizing: border-box;
      color: #fff;
      cursor: pointer;
      display: inline-flex;
      font-family: "JetBrains Mono", monospace;
      height: 48px;
      justify-content: center;
      line-height: 1;
      list-style: none;
      overflow: hidden;
      padding-left: 16px;
      padding-right: 16px;
      position: relative;
      text-align: left;
      text-decoration: none;
      transition: box-shadow 0.15s, transform 0.15s;
      user-select: none;
      -webkit-user-select: none;
      touch-action: manipulation;
      white-space: nowrap;
      will-change: box-shadow, transform;
      font-size: 18px;
    }
    
    .button-primary:focus {
      box-shadow: #3c4fe0 0 0 0 1.5px inset, rgba(45, 35, 66, 0.4) 0 2px 4px, rgba(45, 35, 66, 0.3) 0 7px 13px -3px, #3c4fe0 0 -3px 0 inset;
    }
    
    .button-primary:hover {
      box-shadow: rgba(45, 35, 66, 0.4) 0 4px 8px, rgba(45, 35, 66, 0.3) 0 7px 13px -3px, #3c4fe0 0 -3px 0 inset;
      transform: translateY(-2px);
    }
    
    .button-primary:active {
      box-shadow: #3c4fe0 0 3px 7px inset;
      transform: translateY(2px);
    }
    
    body {
      background-color: #1e4785;
    }
    
    @media print, screen and (max-width: 63.99875em) {
      .col-md {
        font-size: 35px;
      }
    }
    
    /* JAVASCRIPT *************************************************************************************/
    /* FOUNDATION IMPORTS*/
    html {
      visibility: visible;
    }
    
    /*# sourceMappingURL=style.css.map */
    

    可视化:

    DesktopMenu

    Mobile Menu

    感谢所有在此期间试图提供帮助的人。

    【讨论】:

      【解决方案2】:

      在折叠模式(移动)中,汉堡图标功能取决于要包含的所需 javascript 包。 例如,https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js. 此外,在您的标记中,您有一个松散的一个标签(锚).可能它来自于从 bootstrap 网站上的示例中复制而来。

      请参阅以下工作代码。

      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
      <nav id="navbar" class="navbar navbar-light navbar-expand-lg">
        <div class="container-fluid">
          <a class="navbar-brand" href="#"><img class="navbar-brand" src="[[++url_images]]/logos/logo.jpg" alt="Your image is not loading"></a>
          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarScroll" aria-controls="navbarScroll" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon text-dark"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarScroll">
            <ul class="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll" >
              <li class="nav-item">
                <a class="nav-link active home" aria-current="page" href="https://www.google.com">Home</a>
              </li>
              <li class="nav-item">
                <a class="nav-link about" href="https://www.google.com">About us</a>
              </li>
              <li class="nav-item">
                <a class="nav-link contact" href="https://www.google.com">Contact</a>
              </li>
              <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                  Link
                </a>
                <ul class="dropdown-menu" aria-labelledby="navbarScrollingDropdown">
                  <li><a class="dropdown-item" href="https://www.google.com">Action</a></li>
                  <li><a class="dropdown-item" href="https://www.google.com">Another action</a></li>
                  <li>
                    <hr class="dropdown-divider">
                  </li>
                  <li><a class="dropdown-item" href="https://www.google.com">Something else here</a></li>
                </ul>
              </li>
            </ul>
            <form class="d-flex" role="search">
              <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
              <button class="btn btn-outline-success" type="submit">Search</button>
            </form>
          </div>
        </div>
      </nav>

      【讨论】:

      • 你好,谢谢你的回答。 1.正确。 JS 通过我的页脚和引导程序 css 通过页眉加载到每个相关页面上。 2.我会检查你的版本和我的版本,让你知道我发现了什么!
      【解决方案3】:

      我制作了一个可以在 Bootstrap 5 中使用的菜单。它支持多级下拉菜单和子菜单上的列。下拉菜单可以配置为向右或向左扩展。

      字体很棒的 css 被包括在内,但它唯一的功能是添加一个汉堡包图标。

      这已在 Bootstrap 5.2.2 中进行了测试。

      Github - 演示、屏幕和源代码(使用 CSS)

      https://github.com/lasseedsvik/Bootstrap-5-Mega-menu

      这是一个完全“裸”的菜单,没有额外的 CSS

      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
      <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" rel="stylesheet"/>
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"></script>
       <!-- Navigation -->
          <nav class="navbar navbar-expand-lg navbar-light pb-0 col-md-12">
              <a class="navbar-brand mx-4 text-white" href="#">
                  Bootstrap 5.2.2 Mega menu with multilevel dropdowns
              </a>
              <button class="navbar-toggler ms-4 shadow collapsed hamburger" type="button" data-bs-toggle="collapse"
                  data-bs-target="#navbar-content">
                  <i class="fa-solid fa-bars fa-xl text-white"></i>
              </button>
              <div class="menu w-100">
                  <div class="collapse navbar-collapse" id="navbar-content">
                      <ul class="navbar-nav mr-auto mb-lg-0">
                          <li class="nav-item">
                              <a class="nav-link active py-3 px-4" aria-current="page" href="#">Start</a>
                          </li>
      
                          <!-- Multilevel dropdown -->
                          <li class="nav-item dropdown">
                              <a class="nav-link py-3 px-4 dropdown-toggle" href="#" data-bs-toggle="dropdown"
                                  data-bs-auto-close="outside">Multilevel</a>
                              <ul class="dropdown-menu mt-0 shadow">
                                  <li>
                                      <a class="dropdown-item" href="#">Something</a>
                                  </li>
                                  <li class="dropstart">
                                      <a href="#" class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown">Submenu
                                          Left</a>
                                      <ul class="dropdown-menu shadow">
                                          <li>
                                              <a class="dropdown-item" href="#">Link 1</a>
                                          </li>
                                          <li>
                                              <a class="dropdown-item" href="#">Link 2</a>
                                          </li>
                                          <li>
                                              <a class="dropdown-item" href="#">Link 3</a>
                                          </li>
                                          <li>
                                              <a class="dropdown-item" href="#">Link 4</a>
                                          </li>
                                          <li>
                                              <a class="dropdown-item" href="#">Link 5</a>
                                          </li>
                                      </ul>
                                  </li>
                                  <li class="dropend">
                                      <a href="#" class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown"
                                          data-bs-auto-close="outside">
                                          Submenu Right</a>
                                      <ul class="dropdown-menu shadow">
                                          <li>
                                              <a class="dropdown-item" href="">Yoghurt 1</a>
                                          </li>
                                          <li>
                                              <a class="dropdown-item" href="">Yoghurt 2</a>
                                          </li>
                                          <li>
                                              <a class="dropdown-item" href="">Yoghurt 3</a>
                                          </li>
                                          <li class="dropend">
                                              <a href="#" class="dropdown-item dropdown-toggle"
                                                  data-bs-toggle="dropdown">Hamsters</a>
                                              <ul class="dropdown-menu dropdown-submenu shadow">
                                                  <li>
                                                      <a class="dropdown-item" href="#">Hamster 1</a>
                                                  </li>
                                                  <li>
                                                      <a class="dropdown-item" href="#">Hamster 2</a>
                                                  </li>
                                                  <li>
                                                      <a class="dropdown-item" href="#">Hamster 3</a>
                                                  </li>
                                                  <li>
                                                      <a class="dropdown-item" href="#">Hamster 4</a>
                                                  </li>
                                              </ul>
                                          </li>
                                          <li>
                                              <a class="dropdown-item" href="">Yoghurt 4</a>
                                          </li>
                                      </ul>
                                  </li>
                                  <li>
                                      <hr class="dropdown-divider">
                                  </li>
                                  <li><a class="dropdown-item" href="#">Something else here</a></li>
                              </ul>
                          </li>
                          <!-- End Multilevel dropdown -->
                          <li class="nav-item">
                              <a class="nav-link py-3 px-4" href="#">Link</a>
                          </li>
                          <!-- Mega menu -->
                          <li class="nav-item dropdown dropdown-mega position-static">
                              <a class="nav-link dropdown-toggle py-3 px-4" href="#" data-bs-toggle="dropdown"
                                  data-bs-auto-close="outside">Mega menu</a>
                              <div class="dropdown-menu shadow-lg col-lg-12 my-0">
                                  <div class="mega-content px-4">
                                      <div class="container-fluid">
                                          <div class="row justify-content-center">
                                              <div class="col-12 col-md-4 col-lg-3 py-4">
                                                  <h5>Headline 1</h5>
                                                  <div class="list-group">
                                                      <a href="#">Col 1 link</a>
                                                      <a href="#">Col 1 link</a>
                                                      <a href="#">Col 1 link</a>
                                                      <a href="#">Col 1 link</a>
                                                      <a href="#">Col 1 link</a>
                                                      <a href="#">Col 1 link</a>
                                                  </div>
                                              </div>
                                              <div class="col-12 col-md-4 col-lg-3 py-4">
                                                  <h5>Headline 2</h5>
                                                  <div class="list-group">
                                                      <a href="#">Col 2 link</a>
                                                      <a href="#">Col 2 link</a>
                                                      <a href="#">Col 2 link</a>
                                                      <a href="#">Col 2 link</a>
                                                      <a href="#">Col 2 link</a>
                                                  </div>
                                              </div>
                                              <div class="col-12 col-md-4 col-lg-3 py-4">
                                                  <h5>Headline 3</h5>
                                                  <div class="list-group">
                                                      <a href="#">Col 3 link</a>
                                                      <a href="#">Col 3 link</a>
                                                      <a href="#">Col 3 link</a>
                                                      <a href="#">Col 3 link</a>
                                                  </div>
                                              </div>
                                          </div>
                                      </div>
                                  </div>
                              </div>
                          </li>
                          <!--End Mega menu -->
                      </ul>
                  </div>
              </div>
          </nav>
          <!-- End Navigation -->

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-20
        • 2016-11-18
        • 2017-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-03
        • 1970-01-01
        相关资源
        最近更新 更多