Mafere na isi ọdịnaya Gaa na ntugharị docs
in English

Navbar

Akwụkwọ na ihe atụ maka isi igodo ụzọ Bootstrap na-anabata nke ọma, navbar. Gụnyere nkwado maka akara, igodo, na ndị ọzọ, gụnyere nkwado maka ngwa mgbakwunye ọdịda anyị.

Ka o si arụ ọrụ

Nke a bụ ihe ị kwesịrị ịma tupu ịmalite na navbar:

  • Navbars chọrọ akwa mkpuchi .navbarmaka klaasị na-anabata ndakpọ .navbar-expand{-sm|-md|-lg|-xl|-xxl}na agba .
  • Navbars na ihe dị n'ime ha na-agbapụta na ndabara. Gbanwee akpa iji kpachie obosara ha n'ụzọ dị iche iche.
  • Jiri ohere ohere anyị na flex uru klaasị maka ịchịkwa oghere na nhazi n'ime navbars.
  • Navbars na-anabata ya na ndabara, mana ị nwere ike gbanwee ya ngwa ngwa ka ọ gbanwee nke ahụ. Omume nnabata dabere na ngwa mgbakwunye Javascript anyị dara.
  • Gbaa mbọ hụ na ịnweta ya site na iji <nav>mmewere ma ọ bụ, ọ bụrụ na ị na-eji ihe ndị ọzọ dị ka a <div>, tinye a role="navigation"na navbar ọ bụla iji kọwaa ya nke ọma dị ka mpaghara ama ama maka ndị ọrụ teknụzụ enyemaka.
  • Gosi ihe dị ugbu a site na iji aria-current="page"maka ibe dị ugbu a ma ọ bụ aria-current="true"maka ihe dị ugbu a na setịpụ.
Mmetụta animation nke akụrụngwa a dabere na prefers-reduced-motionajụjụ mgbasa ozi. Hụ akụkụ ngagharị ewelatala nke akwụkwọ nnweta anyị .

Ọdịnaya akwadoro

Navbars na-abịa na nkwado arụnyere n'ime ya maka ntakịrị obere akụkụ. Họrọ n'ime ihe ndị a dị ka achọrọ:

  • .navbar-brandmaka ụlọ ọrụ gị, ngwaahịa, ma ọ bụ aha oru ngo.
  • .navbar-navmaka ịnya ụgbọ elu zuru oke na nke dị fechaa (gụnyere nkwado maka ọdịda ọdịda).
  • .navbar-togglermaka iji na ngwa mgbakwunye ọdịda anyị yana omume ngbanwe igodo ndị ọzọ .
  • Flex na spacing utilities maka ụdị ọ bụla njikwa na omume.
  • .navbar-textmaka ịgbakwunye eriri ederede kwụ n'etiti.
  • .collapse.navbar-collapsemaka ichikota na izobe ọdịnaya navbar site na ebe ezumike nne na nna.
  • Tinye nhọrọ .navbar-scrollka ịtọ max-heightma pịgharịa ọdịnaya navbar gbasaara .

Nke a bụ ọmụmaatụ nke akụkụ-akụkụ niile gụnyere na navbar ọkụ na-anabata nke na-ada ozugbo na ebe nkwụsị lg(nnukwu).

<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">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>

Ọmụmaatụ a na-eji klaasị ndabere ( bg-light) na oghere ( my-2, my-lg-0, me-sm-0) my-sm-0klaasị.

Ụdị

Enwere .navbar-brandike itinye ya na ọtụtụ ihe, mana arịlịka na-arụ ọrụ kacha mma, dịka ụfọdụ ihe nwere ike ịchọ klaasị bara uru ma ọ bụ ụdị omenala.

Ederede

Tinye ederede gị n'ime mmewere na .navbar-brandklas.

<!-- 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>

Onyonyo

.navbar-brandỊ nwere ike dochie ederede n'ime <img>.

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

Foto na ederede

Ịnwekwara ike iji ụfọdụ akụrụngwa agbakwunyere tinye onyonyo na ederede n'otu oge. Rịba ama mgbakwunye .d-inline-blockna .align-text-topna <img>.

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

Njikọ igodo Navbar na-eji klaasị mgbanwe nke ha na-ewuli na .navnhọrọ anyị ma chọọ ka e jiri klaasị toggler maka ịke na-anabata nke ọma. Ntugharị na navbars ga-etokwa iji nọrọ n'obere oghere dị ka o kwere mee iji dowe ọdịnaya navbar gị n'otu n'otu nke ọma.

Tinye .activeklas ahụ .nav-linkiji gosi ibe dị ugbu a.

Biko mara na ị ga-agbakwunyekwa aria-currentnjirimara na arụ ọrụ .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">Disabled</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

Ma n'ihi na anyị na-eji klaasị maka ụgbọ mmiri anyị, ị nwere ike zere usoro dabere na ndepụta kpamkpam ma ọ bụrụ na-amasị gị.

<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">Disabled</a>
      </div>
    </div>
  </div>
</nav>

Ị nwekwara ike iji dropdowns na navbar gị. Nchịkọta nhọrọ mwụda chọrọ ihe mkpuchi maka idowe, yabụ jide n'aka na ị na-eji ihe dị iche iche na akwụghị ụgwọ maka .nav-itemyana .nav-linkdị ka egosiri n'okpuru.

<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>

Ụdị

Debe njikwa ụdị dị iche iche na ihe mejupụtara n'ime ụgbọ mmiri:

<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>

Ngwa ngwa ihe ụmụaka na- .navbareji okirikiri nhọrọ ukwuu ga-adabara na justify-content: space-between. Jiri ihe ndị ọzọ na-agbanwe agbanwe dị ka achọrọ iji dozie omume a.

<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>

Otu ntinye na-arụkwa ọrụ. Ọ bụrụ na navbar gị bụ ụdị dum, ma ọ bụ na-abụkarị ụdị, ị nwere ike iji <form>mmewere dị ka akpa wee chekwaa ụfọdụ 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>

A na-akwado bọtịnụ dị iche iche dịka akụkụ nke ụdị navbar ndị a, kwa. Nke a bụkwa ihe ncheta dị ukwuu na enwere ike iji akụrụngwa nhazi kwụ ọtọ iji kwado ihe nha dị iche iche.

<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>

Ederede

Navbars nwere ike ịnwe ntakịrị ederede site na enyemaka nke .navbar-text. Klas a na-edozi nhazi kwụ ọtọ na oghere kwụ ọtọ maka eriri ederede.

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

Gwakọta ma jikọta ya na ihe ndị ọzọ na akụrụngwa dị ka achọrọ.

<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>

Atụmatụ agba

Ịmepụta navbar adịbeghị mfe n'ihi nchikota nke klaasị isiokwu na akụrụngwa background-color. Họrọ .navbar-lightmaka ojiji nwere agba okirikiri dị ọkụ, ma ọ bụ .navbar-darkmaka agba okirikiri gbara ọchịchịrị. Mgbe ahụ, hazie ya na .bg-*utilities.

<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>

Akpa

Ọ bụ ezie na achọghị ya, ị nwere ike kechie navbar n'ime .containerka etiti ya na ibe-n'agbanyeghị na rịba ama na akpa dị n'ime ka achọrọ. Ma ọ bụ ị nwere ike itinye akpa n'ime ka .navbarọ bụrụ naanị n'etiti ọdịnaya nke navbar dị elu ma ọ bụ kwụ ọtọ .

<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>

Jiri igbe ọ bụla na-anabata iji gbanwee etu esi ewepụta ọdịnaya dị na navbar gị.

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

Ndokwa

Jiri akụrụngwa ọnọdụ anyị tinye navbars n'ọkwa na-abụghị static. Họrọ site na edoziri ruo n'elu, nke edobere na ala, ma ọ bụ rapara n'elu (akwụkwọ mpịakọta na ibe ya ruo mgbe ọ ruru n'elu, wee nọrọ ebe ahụ). Navbars edobere anya na-eji position: fixed, nke pụtara na a dọpụrụ ha na DOM nkịtị ma nwee ike chọọ CSS omenala (dịka ọmụmaatụ, padding-topna <body>) iji gbochie iji ihe ndị ọzọ kpuchie ya.

Marakwa na .sticky-topojiji position: stickya na-akwadoghị nke ọma na ihe nchọgharị ọ bụla .

<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>

Na-atụgharị

Tinye .navbar-nav-scrollna .navbar-nav(ma ọ bụ akụkụ nke navbar ọzọ) iji mee ka mpịachi kwụ ọtọ n'ime ọdịnaya nwere ike ịgbanwegharị nke navbar dara ada. Site na ndabara, ịpịgharị na-abanye na 75vh(ma ọ bụ 75% nke ịdị elu nlele), mana ị nwere ike iji akụrụngwa omenala CSS --bs-navbar-heightma ọ bụ ụdị omenala mebie nke ahụ. N'ebe nlele buru ibu mgbe a na-agbasawanye navbar, ọdịnaya ga-apụta dịka ọ na-eme na navbar ndabara.

Biko mara na omume a na-abịa na ihe ndọghachi azụ nke overflow—mgbe ịtọlite overflow-y: auto​​​​(chọrọ ka ịpịgharịa ọdịnaya ebe a), overflow-xbụ ihe nhata nke auto, nke ga-egbutu ụfọdụ ọdịnaya kwụ ọtọ.

Nke a bụ ihe atụ navbar na-eji .navbar-nav-scrollya na style="--bs-scroll-height: 100px;", yana ụfọdụ ngwa mgbakwunye oke maka oghere kacha mma.

<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">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>

Àgwà na-anabata

Navbars nwere ike iji .navbar-toggler, .navbar-collapse, na .navbar-expand{-sm|-md|-lg|-xl|-xxl}klaasị chọpụta mgbe ọdịnaya ha daa n'azụ bọtịnụ. Na mgbakwunye na akụrụngwa ndị ọzọ, ị nwere ike họrọ ngwa ngwa mgbe ị ga-egosi ma ọ bụ zoo ụfọdụ ihe.

Maka ụgbọ mmiri ndị na-adịghị ada ada, tinye .navbar-expandklas na navbar. Maka ụgbọ mmiri na-ada mgbe niile, etinyela .navbar-expandklaasị ọ bụla.

Toggler

Ndị na-atụgharị Navbar na-adakọ aka ekpe site na ndabara, mana ọ bụrụ na ha soro mmemme nwanne dị ka a .navbar-brand, a ga-ahazi ha ozugbo n'aka nri aka nri. Ịtụgharị akara gị ga-atụgharị ntinye nke toggler. N'okpuru bụ ọmụmaatụ ụdị ngbanwe dị iche iche.

Enweghị .navbar-brandegosiri na ebe nkwụsị kacha nta:

<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">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>

Site na aha ika egosiri n'aka ekpe yana toggler n'aka nri:

<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">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>

Ya na toggler n'aka ekpe yana akara aha n'aka nri:

<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">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>

Ọdịnaya nke mpụga

Mgbe ụfọdụ, ịchọrọ iji ngwa mgbakwunye ọdịda iji kpalite mmewere akpa maka ọdịnaya nke na-anọdụ ala na mpụga .navbar. N'ihi na ngwa mgbakwunye anyị na-arụ ọrụ idna data-bs-targetmatching, nke ahụ dị mfe ime!

<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>

Mgbe ị na-eme nke a, anyị na-akwado ịgụnye Javascript agbakwunyere iji bugharịa elekwasị anya na mmemme na akpa mgbe emepere ya. Ma ọ bụghị ya, ndị ọrụ ahụigodo na ndị na-eji teknụzụ enyemaka ga-esiri ike ịchọta ọdịnaya ekpughere ọhụrụ - ọkachasị ma ọ bụrụ na akpa e meghere na-abịa n'ihu onye na-emegharị ihe na nhazi akwụkwọ ahụ. Anyị na-akwadokwa ijide n'aka na toggler nwere aria-controlsnjirimara ahụ, na-atụ aka na idakpa ọdịnaya. Na tiori, nke a na-enye ohere ka ndị ọrụ nka na-enyere aka si na toggler wụpụ ozugbo gaa na akpa ọ na-achịkwa-mana nkwado maka nke a adịchaghị mma ugbu a.

Offcanvas

Tụgharịa navbar na-agbasawanye na nke na-ada ada ka ọ bụrụ drawer offcanvas jiri ngwa mgbakwunye offcanvas. Anyị na-agbatị ma ụdị ndabara nke offcanvas ma jiri .navbar-expand-*klaasị anyị mepụta akụkụ igodo ụzọ na-agbanwe agbanwe na-agbanwe agbanwe.

N'ihe atụ dị n'okpuru, iji mepụta oghere navbar na-apụ apụ nke na-adaba mgbe niile, hapụ .navbar-expand-*klaasị ahụ kpamkpam.

<nav class="navbar navbar-light bg-light fixed-top">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Offcanvas navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbar" aria-controls="offcanvasNavbar">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
      <div class="offcanvas-header">
        <h5 class="offcanvas-title" id="offcanvasNavbarLabel">Offcanvas</h5>
        <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
      </div>
      <div class="offcanvas-body">
        <ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
          <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="offcanvasNavbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
              Dropdown
            </a>
            <ul class="dropdown-menu" aria-labelledby="offcanvasNavbarDropdown">
              <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>
        </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>
  </div>
</nav>

Ka imepụta ihe navbar offcanvas nke na-agbasa ka ọ bụrụ navbar nkịtị n'otu ebe nkwụsịtụ dị ka lg, jiri .navbar-expand-lg.

<nav class="navbar navbar-light navbar-expand-lg bg-light fixed-top">
  <a class="navbar-brand" href="#">Offcanvas navbar</a>
  <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#navbarOffcanvasLg" aria-controls="navbarOffcanvasLg">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="offcanvas offcanvas-end" tabindex="-1" id="navbarOffcanvasLg" aria-labelledby="navbarOffcanvasLgLabel">
    ...
  </div>
</nav>

Sass

Mgbanwe

$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

Navbar na-anabata klaasị gbasaa/dabie (dịka ọmụmaatụ .navbar-expand-lg) na $breakpointsmaapụ wee mepụta ya site na akaghị 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;
        }

        .offcanvas-header {
          display: none;
        }

        .offcanvas {
          position: inherit;
          bottom: 0;
          z-index: 1000;
          flex-grow: 1;
          visibility: visible !important; // stylelint-disable-line declaration-no-important
          background-color: transparent;
          border-right: 0;
          border-left: 0;
          @include transition(none);
          transform: none;
        }
        .offcanvas-top,
        .offcanvas-bottom {
          height: auto;
          border-top: 0;
          border-bottom: 0;
        }

        .offcanvas-body {
          display: flex;
          flex-grow: 0;
          padding: 0;
          overflow-y: visible;
        }
      }
    }
  }
}