Holo i ka ʻike nui Holo i ka hoʻokele docs
in English

Navbar

Nā palapala a me nā hiʻohiʻona no ke poʻomanaʻo hoʻokele ikaika a Bootstrap, ka navbar. Loaʻa i ke kākoʻo no ka hōʻailona ʻana, ka hoʻokele ʻana, a me nā mea hou aku, me ke kākoʻo no kā mākou plugin collapse.

Pehea e hana ai

Eia ka mea e pono ai ʻoe e ʻike ma mua o ka hoʻomaka ʻana me ka navbar:

  • Pono nā Navbars i kahi kāʻei .navbarme .navbar-expand{-sm|-md|-lg|-xl|-xxl}nā papa hāʻule pane a me nā papa kala .
  • ʻO nā Navbars a me kā lākou mau ʻike he wai ma ka paʻamau. E hoʻololi i ka ipu e kaupalena i ko lākou ākea ākea ma nā ʻano like ʻole.
  • E hoʻohana i kā mākou papa hana hoʻokaʻawale a hoʻololi no ka hoʻomalu ʻana i ka spacing a me ke kaulike ʻana i loko o nā navbars .
  • Hoʻololi nā Navbars ma ka maʻamau, akā hiki iā ʻoe ke hoʻololi maʻalahi iā lākou e hoʻololi i kēlā. ʻO ke ʻano pane e pili ana i kā mākou Collapse JavaScript plugin.
  • E hōʻoia i ka loaʻa ʻana ma o ka hoʻohana ʻana i kahi <nav>mea a i ʻole, inā e hoʻohana ana i kahi mea maʻamau e like me ka <div>, e hoʻohui i kahi role="navigation"i kēlā me kēia navbar e hoʻomaopopo maopopo iā ia he ʻāina ʻāina no nā mea hoʻohana i nā ʻenehana kōkua.
  • E hōʻike i ka mea o kēia manawa ma ka hoʻohana ʻana aria-current="page"no ka ʻaoʻao o kēia manawa a i ʻole aria-current="true"ka mea i kēia manawa i kahi set.
ʻO ka hopena animation o kēia māhele e pili ana i ka prefers-reduced-motionnīnau media. E ʻike i ka ʻāpana hoʻohaʻahaʻa o kā mākou palapala hiki ke komo .

Maʻiʻo i kākoʻo ʻia

Hele mai nā Navbars me ke kākoʻo i kūkulu ʻia no ka liʻiliʻi o nā ʻāpana. E koho mai i ka mea e pono ai:

  • .navbar-brandno kāu hui, huahana, a i ʻole inoa papahana.
  • .navbar-navno ka hoʻokele piha kiʻekiʻe a me ka māmā (me ke kākoʻo no nā hāʻule iho).
  • .navbar-togglerno ka hoʻohana ʻana me kā mākou plugin collapse a me nā ʻano hoʻokele hoʻokele ʻē aʻe .
  • Hoʻololi a me ka hoʻokaʻawale ʻana i nā pono no kēlā me kēia ʻano kaohi a me nā hana.
  • .navbar-textno ka hoʻohui ʻana i nā kaula kikoʻī o ka kikokikona.
  • .collapse.navbar-collapseno ka hui pū ʻana a me ka hūnā ʻana i nā maʻiʻo o ka navbar e kahi ʻāpana makua.
  • E hoʻohui i kahi koho .navbar-scrolle hoʻonoho i kahi max-heightmaʻiʻo navbar i hoʻonui ʻia .

Eia kekahi laʻana o nā ʻāpana ʻāpana āpau i hoʻokomo ʻia i loko o kahi navbar hoʻonaʻauao māmā e hāʻule ʻakomi i ka wahi haʻi lg(nui).

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
          </ul>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <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>

Ke hoʻohana nei kēia hiʻohiʻona i nā papa hoʻohana hope ( bg-light) a me ka spacing ( my-2, my-lg-0, me-sm-0, my-sm-0).

Brand

Hiki .navbar-brandke hoʻohana ʻia i ka hapa nui o nā mea, akā ʻoi aku ka maikaʻi o kahi heleuma, no ka mea e koi ana kekahi mau mea i nā papa pono a i ʻole nā ​​​​ʻano maʻamau.

kikokikona

Hoʻohui i kāu kikokikona i loko o kahi mea me ka .navbar-brandpapa.

<!-- As a link -->
<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
  </div>
</nav>

<!-- As a heading -->
<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <span class="navbar-brand mb-0 h1">Navbar</span>
  </div>
</nav>

Kiʻi

Hiki iā ʻoe ke pani i ka kikokikona i loko o ka .navbar-brandme kahi <img>.

<nav class="navbar navbar-light bg-light">
  <div class="container">
    <a class="navbar-brand" href="#">
      <img src="/docs/5.0/assets/brand/bootstrap-logo.svg" alt="" width="30" height="24">
    </a>
  </div>
</nav>

Kiʻi a me ka kikokikona

Hiki iā ʻoe ke hoʻohana i kekahi mau mea pono e hoʻohui i kahi kiʻi a me kahi kikokikona i ka manawa like. E nānā i ka hoʻohui ʻana o .d-inline-blocka .align-text-topma ka <img>.

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">
      <img src="/docs/5.0/assets/brand/bootstrap-logo.svg" alt="" width="30" height="24" class="d-inline-block align-text-top">
      Bootstrap
    </a>
  </div>
</nav>

Hoʻokumu nā loulou hoʻokele Navbar i kā mākou mau .navkoho me kā lākou papa hoʻololi ponoʻī a koi aku i ka hoʻohana ʻana i nā papa toggler no ke ʻano pane kūpono. E ulu pū ana ka hoʻokele ma nā navbar e noho i kahi ākea ākea e hiki ai ke hoʻopaʻa paʻa i kāu ʻike navbar.

Hoʻohui i ka .activepapa .nav-linke hōʻike i ka ʻaoʻao o kēia manawa.

E ʻoluʻolu, pono ʻoe e hoʻohui i ke aria-currentʻano ma ka active .nav-link.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Features</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Pricing</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

A no ka mea, hoʻohana mākou i nā papa no kā mākou navs, hiki iā ʻoe ke pale i ka papa inoa-papa inoa holoʻokoʻa inā makemake ʻoe.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
      <div class="navbar-nav">
        <a class="nav-link active" aria-current="page" href="#">Home</a>
        <a class="nav-link" href="#">Features</a>
        <a class="nav-link" href="#">Pricing</a>
        <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </div>
    </div>
  </div>
</nav>

Hiki iā ʻoe ke hoʻohana i nā dropdown i kāu navbar. Pono nā menus dropdown i kahi mea hoʻopili no ka hoʻonohonoho ʻana, no laila e hoʻohana pono i nā mea ʻokoʻa a pūnana no .nav-itema .nav-linke like me ka mea i hōʻike ʻia ma lalo nei.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNavDropdown">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Features</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Pricing</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown link
          </a>
          <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
            <li><a class="dropdown-item" href="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
          </ul>
        </li>
      </ul>
    </div>
  </div>
</nav>

Nā palapala

E kau i nā ʻano mana like ʻole a me nā ʻāpana i loko o kahi navbar:

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <form class="d-flex">
      <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>
</nav>

E hoʻohana i nā ʻano keiki ponoʻī e .navbarhoʻohana i ka hoʻonohonoho flex a e paʻa i ka justify-content: space-between. E hoʻohana i nā pono hana maʻalahi e like me ka mea e pono ai e hoʻoponopono i kēia ʻano.

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand">Navbar</a>
    <form class="d-flex">
      <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>
</nav>

Hana pū kekahi pūʻulu hoʻokomo. Inā he ʻano holoʻokoʻa kāu navbar, a i ʻole he ʻano nui, hiki iā ʻoe ke hoʻohana i ka <form>mea e like me ka ipu a mālama i kekahi HTML.

<nav class="navbar navbar-light bg-light">
  <form class="container-fluid">
    <div class="input-group">
      <span class="input-group-text" id="basic-addon1">@</span>
      <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
    </div>
  </form>
</nav>

Kākoʻo ʻia nā pihi like ʻole ma ke ʻano o kēia mau ʻano navbar. He mea hoʻomanaʻo maikaʻi hoʻi kēia e hiki ke hoʻohana ʻia nā pono hana alignment vertical e hoʻohālikelike i nā mea nui like ʻole.

<nav class="navbar navbar-light bg-light">
  <form class="container-fluid justify-content-start">
    <button class="btn btn-outline-success me-2" type="button">Main button</button>
    <button class="btn btn-sm btn-outline-secondary" type="button">Smaller button</button>
  </form>
</nav>

kikokikona

Loaʻa i nā Navbars nā ʻāpana kikokikona me ke kōkua o .navbar-text. Hoʻoponopono kēia papa i ka hoʻopololei kū pololei a me ka hoʻokaʻawale ʻana i nā kaula o ke kikokikona.

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <span class="navbar-text">
      Navbar text with an inline element
    </span>
  </div>
</nav>

Hoʻohui a hoʻohālikelike me nā mea ʻē aʻe a me nā pono hana e like me ka mea e pono ai.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar w/ text</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Features</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Pricing</a>
        </li>
      </ul>
      <span class="navbar-text">
        Navbar text with an inline element
      </span>
    </div>
  </div>
</nav>

Nā kala kala

ʻAʻole i maʻalahi ka hana ʻana i ka navbar ma muli o ka hui pū ʻana o nā papa kumuhana a me background-colornā pono hana. E koho mai .navbar-lightno ka hoʻohana ʻana me nā kala ʻulaʻula, a i ʻole .navbar-darkno nā kala ʻeleʻele. A laila, hoʻonohonoho me .bg-*nā mea hoʻohana.

<nav class="navbar navbar-dark bg-dark">
  <!-- Navbar content -->
</nav>

<nav class="navbar navbar-dark bg-primary">
  <!-- Navbar content -->
</nav>

<nav class="navbar navbar-light" style="background-color: #e3f2fd;">
  <!-- Navbar content -->
</nav>

Nā pahu pahu

ʻOiai ʻaʻole koi ʻia, hiki iā ʻoe ke hoʻopaʻa i kahi navbar i loko o kahi .containerkikowaena ma kahi ʻaoʻao-ʻoiai e hoʻomaopopo ʻoe e koi ʻia kahi pahu i loko. A i ʻole hiki iā ʻoe ke hoʻohui i kahi pahu i loko o ka mea .navbare hoʻokomo wale i nā ʻike o kahi navbar luna paʻa a paʻa paha .

<div class="container">
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container-fluid">
      <a class="navbar-brand" href="#">Navbar</a>
    </div>
  </nav>
</div>

E hoʻohana i kekahi o nā pahu pane e hoʻololi i ka laulā o ka ʻike ma kāu navbar i hōʻike ʻia.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-md">
    <a class="navbar-brand" href="#">Navbar</a>
  </div>
</nav>

Hoʻokomo

E hoʻohana i kā mākou mau pono kūlana e kau i nā navbars i nā kūlana non-static. E koho mai ka hoʻopaʻa ʻana i luna, hoʻopaʻa ʻia i lalo, a i ʻole i hoʻopaʻa ʻia i luna (e ʻōwili me ka ʻaoʻao a hiki i luna, a laila noho ma laila). Hoʻohana ʻia nā navbars paʻa position: fixed, ʻo ia hoʻi, ua huki ʻia lākou mai ke kahe maʻamau o ka DOM a makemake paha i ka CSS maʻamau (e laʻa, padding-topma ka <body>) e pale ai i ka uhi ʻana me nā mea ʻē aʻe.

E hoʻomaopopo hoʻi i ka .sticky-tophoʻohana ʻana position: sticky, ʻaʻole i kākoʻo piha ʻia i kēlā me kēia polokalamu kele pūnaewele .

<nav class="navbar navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Default</a>
  </div>
</nav>
<nav class="navbar fixed-top navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Fixed top</a>
  </div>
</nav>
<nav class="navbar fixed-bottom navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Fixed bottom</a>
  </div>
</nav>
<nav class="navbar sticky-top navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Sticky top</a>
  </div>
</nav>

Owili

Hoʻohui .navbar-nav-scrolli kahi .navbar-nav(a i ʻole ʻāpana navbar ʻē aʻe) e hiki ai i ka ʻōwili kū pololei i loko o nā mea hiki ke hoʻololi ʻia o kahi navbar hāʻule. ʻO ka mea paʻamau, hoʻomaka ka ʻōwili ʻana ma 75vh(a i ʻole 75% o ke kiʻekiʻe o ka viewport), akā hiki iā ʻoe ke hoʻopau i kēlā me ka waiwai maʻamau CSS kūloko --bs-navbar-heighta i ʻole nā ​​​​ʻano maʻamau. Ma nā puka ʻike nui ke hoʻonui ʻia ka navbar, e ʻike ʻia ka ʻike e like me ia ma kahi navbar paʻamau.

E ʻoluʻolu e hele mai kēia ʻano me kahi drawback o overflow—i ka hoʻonohonoho ʻana overflow-y: auto(pono e ʻōwili i ka maʻiʻo ma aneʻi), overflow-xʻo ia ka mea like me auto, e ʻoki i kekahi maʻiʻo ākea.

Eia kekahi laʻana navbar e hoʻohana ana .navbar-nav-scrollme style="--bs-scroll-height: 100px;", me kekahi mau mea pono palena palena ʻē aʻe no ka spacing maikaʻi loa.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar scroll</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" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</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="#">Action</a></li>
            <li><a class="dropdown-item" href="#">Another action</a></li>
            <li><hr class="dropdown-divider"></li>
            <li><a class="dropdown-item" href="#">Something else here</a></li>
          </ul>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Link</a>
        </li>
      </ul>
      <form class="d-flex">
        <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>

Nā hana pane

Hiki i nā Navbars ke hoʻohana i ka .navbar-toggler, .navbar-collapse, a me .navbar-expand{-sm|-md|-lg|-xl|-xxl}nā papa e hoʻoholo ai i ka wā e hāʻule ai kā lākou ʻike ma hope o kahi pihi. I ka hui pū ʻana me nā pono hana ʻē aʻe, hiki iā ʻoe ke koho maʻalahi i ka wā e hōʻike ai a hūnā i nā mea kikoʻī.

No nā navbar ʻaʻole e hāʻule, hoʻohui i ka .navbar-expandpapa ma ka navbar. No nā navbar e hāʻule mau ana, mai hoʻohui i kekahi .navbar-expandpapa.

Mea hoʻololi

Hoʻopaʻa ʻia nā mea hoʻololi Navbar ma ke ʻano paʻamau, akā inā e hahai lākou i kahi ʻāpana kaikaina e like me ka .navbar-brand, e hoʻopili ʻia lākou i ka ʻaoʻao ʻākau loa. ʻO ka hoʻohuli ʻana i kāu markup e hoʻohuli i ke kau ʻana o ka mea hoʻololi. Aia ma lalo nā laʻana o nā ʻano hoʻololi like ʻole.

Me ka .navbar-brandhōʻike ʻole ʻia ma ka wahi haʻi liʻiliʻi loa:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarTogglerDemo01">
      <a class="navbar-brand" href="#">Hidden brand</a>
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <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>

Me ka inoa hōʻailona i hōʻike ʻia ma ka hema a me ka toggle ma ka ʻākau:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <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>

Me ka mea hoʻololi ma ka hema a me ka inoa inoa ma ka ʻākau:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <a class="navbar-brand" href="#">Navbar</a>
    <div class="collapse navbar-collapse" id="navbarTogglerDemo03">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
        </li>
      </ul>
      <form class="d-flex">
        <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>

Maʻiʻo waho

I kekahi manawa makemake ʻoe e hoʻohana i ka plugin collapse e hoʻomaka i kahi mea pahu no ka ʻike e noho ana ma waho o ka .navbar. No ka mea e hana ana kā mākou plugin i ka ida me ka data-bs-targethoʻohālikelike ʻana, maʻalahi ia hana!

<div class="collapse" id="navbarToggleExternalContent">
  <div class="bg-dark p-4">
    <h5 class="text-white h4">Collapsed content</h5>
    <span class="text-muted">Toggleable via the navbar brand.</span>
  </div>
</div>
<nav class="navbar navbar-dark bg-dark">
  <div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
  </div>
</nav>

Ke hana ʻoe i kēia, manaʻo mākou e hoʻokomo i ka JavaScript hou e hoʻoneʻe i ka manaʻo programmatically i ka ipu ke wehe ʻia. A i ʻole, paʻakikī paha nā mea hoʻohana keyboard a me nā mea hoʻohana i nā ʻenehana kōkua i ka ʻimi ʻana i ka ʻike hou i hōʻike ʻia - ʻoiai inā ʻo ka ipu i wehe ʻia ma mua o ka mea hoʻololi i ke ʻano o ka palapala. Manaʻo pū mākou e hōʻoia i ka mea hoʻololi i ke ʻano aria-controls, e kuhikuhi ana i ka idpahu maʻiʻo. Ma ke kumumanaʻo, ʻae kēia i nā mea hoʻohana ʻenehana kōkua e lele pololei mai ka toggler a i ka ipu āna e hoʻomalu ai - akā paʻakikī ke kākoʻo no kēia.

Sass

Nā mea hoʻololi

$navbar-padding-y:                  $spacer * .5;
$navbar-padding-x:                  null;

$navbar-nav-link-padding-x:         .5rem;

$navbar-brand-font-size:            $font-size-lg;
// Compute the navbar-brand padding-y so the navbar-brand will have the same height as navbar-text and nav-link
$nav-link-height:                   $font-size-base * $line-height-base + $nav-link-padding-y * 2;
$navbar-brand-height:               $navbar-brand-font-size * $line-height-base;
$navbar-brand-padding-y:            ($nav-link-height - $navbar-brand-height) * .5;
$navbar-brand-margin-end:           1rem;

$navbar-toggler-padding-y:          .25rem;
$navbar-toggler-padding-x:          .75rem;
$navbar-toggler-font-size:          $font-size-lg;
$navbar-toggler-border-radius:      $btn-border-radius;
$navbar-toggler-focus-width:        $btn-focus-width;
$navbar-toggler-transition:         box-shadow .15s ease-in-out;
$navbar-dark-color:                 rgba($white, .55);
$navbar-dark-hover-color:           rgba($white, .75);
$navbar-dark-active-color:          $white;
$navbar-dark-disabled-color:        rgba($white, .25);
$navbar-dark-toggler-icon-bg:       url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-dark-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");
$navbar-dark-toggler-border-color:  rgba($white, .1);

$navbar-light-color:                rgba($black, .55);
$navbar-light-hover-color:          rgba($black, .7);
$navbar-light-active-color:         rgba($black, .9);
$navbar-light-disabled-color:       rgba($black, .3);
$navbar-light-toggler-icon-bg:      url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-light-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");
$navbar-light-toggler-border-color: rgba($black, .1);

$navbar-light-brand-color:                $navbar-light-active-color;
$navbar-light-brand-hover-color:          $navbar-light-active-color;
$navbar-dark-brand-color:                 $navbar-dark-active-color;
$navbar-dark-brand-hover-color:           $navbar-dark-active-color;

Loop

Hoʻohui ʻia nā papa navbar pane hoʻonui/holo (e laʻa, .navbar-expand-lg) me ka $breakpointspalapala ʻāina a hana ʻia ma o ka loop i scss/_navbar.scss.

// Generate series of `.navbar-expand-*` responsive classes for configuring
// where your navbar collapses.
.navbar-expand {
  @each $breakpoint in map-keys($grid-breakpoints) {
    $next: breakpoint-next($breakpoint, $grid-breakpoints);
    $infix: breakpoint-infix($next, $grid-breakpoints);

    // stylelint-disable-next-line scss/selector-no-union-class-name
    &#{$infix} {
      @include media-breakpoint-up($next) {
        flex-wrap: nowrap;
        justify-content: flex-start;

        .navbar-nav {
          flex-direction: row;

          .dropdown-menu {
            position: absolute;
          }

          .nav-link {
            padding-right: $navbar-nav-link-padding-x;
            padding-left: $navbar-nav-link-padding-x;
          }
        }

        .navbar-nav-scroll {
          overflow: visible;
        }

        .navbar-collapse {
          display: flex !important; // stylelint-disable-line declaration-no-important
          flex-basis: auto;
        }

        .navbar-toggler {
          display: none;
        }
      }
    }
  }
}