Main content ah kal rawh Docs navigation ah kal rawh
Check
in English

Navbar a ni

Bootstrap-a navigation header chak tak, chhanna pe thei, navbar atana documentation leh entirnan. Branding, navigation leh a dangte support a keng tel a, kan collapse plugin support pawh a tel bawk.

A hnathawh dan

Navbar i hman tan hmaa i hriat tur chu hetiang hi a ni:

  • Navbars hian responsive collapsing leh color scheme class hrang hrang atan wrapping .navbarwith a mamawh a..navbar-expand{-sm|-md|-lg|-xl|-xxl}
  • Navbar leh a chhunga thil awmte hi default-in fluid a ni. Container chu an horizontal width chu kawng hrang hranga tihtlem turin thlak rawh .
  • Navbar chhunga spacing leh alignment control nan kan spacing leh flex utility class te hmang rawh.
  • Navbars hi default-in a chhang thei a, mahse chu chu i thlak danglam theih nan awlsam takin i siam danglam thei bawk. Responsive behavior hi kan Collapse JavaScript plugin ah a innghat a ni.
  • Element hmangin accessibility ensure <nav>emaw, a ang chi element generic zawk hman a nih chuan navbar tinah <div>a dah belh la, assistive technology hmangtute tan landmark region anga chiang taka hriat theih nan.role="navigation"
  • aria-current="page"Tuna thil awm mek chu page awm mek aria-current="true"atan emaw, set pakhata thil awm mek atan emaw hmangin entir rawh .
  • v5.2.0-a thil thar: Navbars hi CSS variable hmanga theme theih a ni a, chu chu .navbarbase class-a scope a ni. .navbar-lightchu deprecated a ni tawh a, .navbar-darkstyle dang dah belh ai chuan CSS variable override turin ziah thar a ni tawh bawk.
He component hian animation effect hi prefers-reduced-motionmedia query ah a innghat a ni. Kan accessibility documentation a reduced motion tih hi en la .

Supported content a awm bawk

Navbars ah hian sub-component tlemte tan built-in support a awm a. A tul angin a hnuaia mi zingah hian thlang rawh:

  • .navbar-brandi company, i thil siam, i project hming atan.
  • .navbar-navfull-height leh lightweight navigation atan (dropdown support te pawh a tel).
  • .navbar-togglerkan collapse plugin leh navigation toggling behavior dangte nena hman tur.
  • Form control leh action eng pawh atan flex leh spacing utilities te.
  • .navbar-textthuziak vertically centered string dah belh nan.
  • .collapse.navbar-collapseparent breakpoint hmanga navbar contents group leh thup nan.
  • Optional dah la, .navbar-scrolla set a max-height, expanded navbar content scroll rawh .

Hetah hian responsive light-themed navbar-a sub-component awm zawng zawng entir nan kan rawn tarlang e, chu chu lg(large) breakpoint-ah automatic-in a collapse vek a ni.

html tih a ni
<nav class="navbar navbar-expand-lg 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="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown
          </a>
          <ul class="dropdown-menu">
            <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" 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>

He entirnan hian background ( bg-light) leh spacing ( me-auto, mb-2, mb-lg-0, me-2) utility class te a hmang a.

Chhinchhiah

The hi .navbar-brandelement tam zawkah hman theih a ni a, mahse anchor hian hna a thawk tha ber a, element thenkhatah chuan utility class emaw custom style emaw a ngai mai thei.

Thumal

.navbar-brandClass nen element pakhat chhungah i text kha dah la .

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

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

Thlalak

A chhunga thuziak .navbar-brandchu <img>.

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

Image leh text

Tin, a ruala image leh text dah belh nan utility dang thenkhat i hmang thei bawk. .d-inline-blockA tih belh leh .align-text-topa chungah hian chhinchhiah rawh <img>.

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

Navbar navigation link te hian kan .navoption te hmangin anmahni modifier class hmangin an siam a, responsive styling dik tak neih nan toggler class hman a ngai a ni. Navbar-a navigation pawh a lo thang lian ang a, i navbar chhunga thu awmte chu him taka a inmil theih nan horizontal space a tam thei ang ber luah turin a pung ang.

Tuna page awm mek tarlan nan .activeclass on kha add rawh ..nav-link

aria-currentActive ah pawh attribute kha i dah tel tur a ni tih hre reng ang che .nav-link.

html tih a ni
<nav class="navbar navbar-expand-lg 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>

Tin, kan navs atan class kan hman avangin i duh chuan list-based approach hi i pumpelh vek thei bawk.

html tih a ni
<nav class="navbar navbar-expand-lg 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>

I navbar ah dropdown te pawh i hmang thei bawk. Dropdown menu-ah hian positioning atan wrapping element a ngai a, chuvangin a hnuaia tarlan ang hian element hrang hrang leh nested element hmang ngei ang che .nav-item..nav-link

html tih a ni
<nav class="navbar navbar-expand-lg 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="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Dropdown link
          </a>
          <ul class="dropdown-menu">
            <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>

Form hrang hrang

Navbar chhungah form control leh component hrang hrang dah rawh:

html tih a ni
<nav class="navbar bg-light">
  <div class="container-fluid">
    <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>
</nav>

Immediately child elements of .navbaruse flex layout leh default ah a awm ang justify-content: space-between. Hetiang thiltih hi siamrem nan a tul angin flex utility dang hmang bawk ang che .

html tih a ni
<nav class="navbar bg-light">
  <div class="container-fluid">
    <a class="navbar-brand">Navbar</a>
    <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>
</nav>

Input group te pawhin hna an thawk ve bawk. I navbar chu form pum pui a nih chuan, a tam zawk chu form a nih chuan <form>element chu container atan i hmang thei a, HTML thenkhat i save thei bawk.

html tih a ni
<nav class="navbar 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>

Heng navbar form hrang hrangah hian button hrang hrang a support bawk. Hei hi vertical alignment utility hmangin element size hrang hrang align theih a nih thu pawh hriat nawn tirtu ropui tak a ni.

html tih a ni
<nav class="navbar 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>

Thumal

Navbars ah hian bits of text a awm thei a, chu chu .navbar-text. He class hian text string hrang hrangte tan vertical alignment leh horizontal spacing a siamrem thin.

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

A tul angin component leh utility dang nen mix leh match rawh.

html tih a ni
<nav class="navbar navbar-expand-lg 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>

Color scheme hrang hrang te

v5.2.0-a thil thar: Navbar theming hi CSS variable hmanga siam .navbar-lighta ni tawh a, hman tawh loh a ni tawh. CSS variable te hi , ah hian hman a ni a .navbar, “light” appearance ah default a ni a, , hmangin override theih a ni .navbar-darkbawk.

Bootstrap-in Sass leh CSS variable a dahkhawm avangin Navbar theme hi a hma aia awlsam zawk a ni. Default chu kan “light navbar” a ni a, background color light nena hman tur a ni a, mahse .navbar-darkdark background color pawh i apply thei bawk. .bg-*Tichuan, utilities hmangin customize rawh.

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

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

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

Container te pawh a awm

.containerA ngai lo nain, page pakhata center turin navbar chu a-ah i wrap thei a ni –inner container a la mamawh tho tih hre reng ang che. A nih loh leh fixed emaw static top navbar.navbar chhunga thil awmte chu center-ah chauh dah turin container chhungah i dah thei bawk.

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

Responsive container eng pawh hmang la, i navbar-a thu awmte chu engzat nge a zau tih thlak rawh.

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

Hmun dahna tur

Kan position utilities hmangin navbar te chu non-static position ah dah rawh. Fixed to the top, fixed to the bottom, stickied to the top (page nen a chung lam a thlen thlengin a scroll a, chutah chuan a awm reng ang), a nih loh leh a hnuai lamah a stick (a hnuai lam a thlen thlengin a scroll a, chutah chuan a awm reng ang) atang hian thlang rawh sawtah).

Fixed navbars use position: fixed, chu chu DOM-a normal flow atanga lak chhuah an ni tihna a ni a, element dangte nena overlap loh nan custom CSS (eg, padding-topon the ) a mamawh thei bawk.<body>

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

Scroll a ni

Navbar collapsed-a toggleable contents chhunga vertical scrolling awm theihna .navbar-nav-scrollturin a .navbar-nav(or navbar sub-component dang) ah dah rawh. Default-ah chuan scrolling chu 75vh(or viewport height 75%)-ah a kick in a, mahse chu chu local CSS custom property --bs-navbar-heightemaw custom styles emaw hmangin i override thei a ni. Viewport lian zawkah chuan navbar tihzauh a nih chuan default navbar-a a lan angin content a lang ang.

Khawngaihin, he thiltih hian harsatna awm thei a keng tel tih hre reng ang che overflow—when setting overflow-y: auto(hetah hian content scroll tur a ngai), overflow-xis the equivalent of auto, chu chuan horizontal content thenkhat a crop ang.

Hetah hian entirnan navbar hmanga .navbar-nav-scrollwith style="--bs-scroll-height: 100px;", extra margin utility thenkhat nen optimum spacing atan kan rawn tarlang e.

html tih a ni
<nav class="navbar navbar-expand-lg 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="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
            Link
          </a>
          <ul class="dropdown-menu">
            <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" 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>

Chhanna pe thei nungchang

Navbars hian .navbar-toggler, .navbar-collapse, leh .navbar-expand{-sm|-md|-lg|-xl|-xxl}class te hmangin an content chu button hnung lama a collapse hun tur a hriat theih a ni. Utility dang nena inzawm chuan awlsam takin element bikte engtikah nge i lantir dawn emaw, i thup dawn emaw tih i thlang thei a ni.

Navbar collap ngai lo tan chuan .navbar-expandnavbar ah class kha add la. Navbar collapse reng thin tan chuan .navbar-expandclass engmah add suh.

Toggler a ni

Navbar togglers te hi default-in left-aligned an ni a, mahse sibling element ang chi an zawm a nih chuan .navbar-brandright right-ah automatic-in an align ang. I markup reverse chuan toggler dahna chu a reverse ang. A hnuaia tarlan te hi toggle style hrang hrang entir a ni.

.navbar-brandBreakpoint tenau ber ah no show a awm lo:

html tih a ni
<nav class="navbar navbar-expand-lg 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" 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>

A vei lamah brand hming a lang a, ding lamah toggler a awm bawk:

html tih a ni
<nav class="navbar navbar-expand-lg 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" 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>

Vei lamah toggler leh dinglamah brand name awmin:

html tih a ni
<nav class="navbar navbar-expand-lg 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" 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>

Pawn lam thil awmte

A châng chuan collapse plugin hmangin structurally sits outside of the content atan container element trigger i duh ṭhin .navbar. Kan plugin hian idand data-bs-targetmatching ah hna a thawh avangin chu chu awlsam takin a ti thei!

html tih a ni
<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>

Chutianga i tih hunah chuan a hawn hunah focus chu programmatically-in container-ah i sawn theih nan JavaScript dang dah belh turin kan rawt a che. Chutiang a nih loh chuan keyboard hmangtute leh assistive technology hmangtute chuan thu thar an hmuh chu an harsat phah mai thei - a bik takin container hawn chu document structure-a toggler hmaa a lo kal chuan. Tin, toggler hian aria-controlsattribute a neih ngei ngei tur a ni tih kan rawt bawk a, chu chu idof the content container-ah a kawhhmuh a ni. Theory-ah chuan, hei hian assistive technology hmangtute chu toggler atanga a control container-ah direct-in a zuang lut thei a–mahse tunah chuan hei hi thlawpna chu a patchy hle.

Offcanvas ah a awm

I expanding leh collapsing navbar chu offcanvas component hmangin offcanvas drawer ah chantir rawh . Offcanvas default style pahnih kan extend a, kan .navbar-expand-*class te hmangin dynamic leh flexible navigation sidebar kan siam bawk.

A hnuaia entirnan hian breakpoint zawng zawnga collapsed reng thin offcanvas navbar siam tur chuan .navbar-expand-*class chu paih vek tur a ni.

html tih a ni
<nav class="navbar 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" 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="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
              Dropdown
            </a>
            <ul class="dropdown-menu">
              <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" 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>
  </div>
</nav>

Offcanvas navbar siam tur chuan breakpoint bik ah normal navbar ah a inzar pharh ang lga, .navbar-expand-lg.

<nav class="navbar 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>

Navbar thim takah offcanvas i hman hian, text chhiar theih loh a nih loh nan offcanvas content-ah background dum i neih a ngai mai thei tih hre reng ang che. A hnuaia entirnan hian offcanvas dum hmanga styling dik tak neih theih nan and to the , to the , to , .navbar-darkleh to kan dah belh a ni..bg-dark.navbar.text-bg-dark.offcanvas.dropdown-menu-dark.dropdown-menu.btn-close-white.btn-close

html tih a ni
<nav class="navbar navbar-dark bg-dark fixed-top">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Offcanvas dark navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="offcanvas offcanvas-end text-bg-dark" tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
      <div class="offcanvas-header">
        <h5 class="offcanvas-title" id="offcanvasDarkNavbarLabel">Dark offcanvas</h5>
        <button type="button" class="btn-close btn-close-white" 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="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
              Dropdown
            </a>
            <ul class="dropdown-menu dropdown-menu-dark">
              <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" role="search">
          <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
          <button class="btn btn-success" type="submit">Search</button>
        </form>
      </div>
    </div>
  </div>
</nav>

CSS a ni

Variables te pawh a awm

v5.2.0 ah dah belh a ni

Bootstrap-in CSS variables approach a kalpui mek zingah hian navbars te hian local CSS variables on hmangin .navbarreal-time customization tihchangtlun nan an hmang ta a ni. CSS variable hrang hrangte tana value te hi Sass hmanga set a nih avangin Sass customization pawh a la support reng bawk.

  --#{$prefix}navbar-padding-x: #{if($navbar-padding-x == null, 0, $navbar-padding-x)};
  --#{$prefix}navbar-padding-y: #{$navbar-padding-y};
  --#{$prefix}navbar-color: #{$navbar-light-color};
  --#{$prefix}navbar-hover-color: #{$navbar-light-hover-color};
  --#{$prefix}navbar-disabled-color: #{$navbar-light-disabled-color};
  --#{$prefix}navbar-active-color: #{$navbar-light-active-color};
  --#{$prefix}navbar-brand-padding-y: #{$navbar-brand-padding-y};
  --#{$prefix}navbar-brand-margin-end: #{$navbar-brand-margin-end};
  --#{$prefix}navbar-brand-font-size: #{$navbar-brand-font-size};
  --#{$prefix}navbar-brand-color: #{$navbar-light-brand-color};
  --#{$prefix}navbar-brand-hover-color: #{$navbar-light-brand-hover-color};
  --#{$prefix}navbar-nav-link-padding-x: #{$navbar-nav-link-padding-x};
  --#{$prefix}navbar-toggler-padding-y: #{$navbar-toggler-padding-y};
  --#{$prefix}navbar-toggler-padding-x: #{$navbar-toggler-padding-x};
  --#{$prefix}navbar-toggler-font-size: #{$navbar-toggler-font-size};
  --#{$prefix}navbar-toggler-icon-bg: #{escape-svg($navbar-light-toggler-icon-bg)};
  --#{$prefix}navbar-toggler-border-color: #{$navbar-light-toggler-border-color};
  --#{$prefix}navbar-toggler-border-radius: #{$navbar-toggler-border-radius};
  --#{$prefix}navbar-toggler-focus-width: #{$navbar-toggler-focus-width};
  --#{$prefix}navbar-toggler-transition: #{$navbar-toggler-transition};
  

CSS variable dang thenkhat pawh hetiang hian a awm bawk .navbar-nav:

  --#{$prefix}nav-link-padding-x: 0;
  --#{$prefix}nav-link-padding-y: #{$nav-link-padding-y};
  @include rfs($nav-link-font-size, --#{$prefix}nav-link-font-size);
  --#{$prefix}nav-link-font-weight: #{$nav-link-font-weight};
  --#{$prefix}nav-link-color: var(--#{$prefix}navbar-color);
  --#{$prefix}nav-link-hover-color: var(--#{$prefix}navbar-hover-color);
  --#{$prefix}nav-link-disabled-color: var(--#{$prefix}navbar-disabled-color);
  

CSS variable hmanga customization chu .navbar-darkCSS selector duplicate dah tel lovin value bik kan override na class-ah kan hmu thei.

  --#{$prefix}navbar-color: #{$navbar-dark-color};
  --#{$prefix}navbar-hover-color: #{$navbar-dark-hover-color};
  --#{$prefix}navbar-disabled-color: #{$navbar-dark-disabled-color};
  --#{$prefix}navbar-active-color: #{$navbar-dark-active-color};
  --#{$prefix}navbar-brand-color: #{$navbar-dark-brand-color};
  --#{$prefix}navbar-brand-hover-color: #{$navbar-dark-brand-hover-color};
  --#{$prefix}navbar-toggler-border-color: #{$navbar-dark-toggler-border-color};
  --#{$prefix}navbar-toggler-icon-bg: #{escape-svg($navbar-dark-toggler-icon-bg)};
  

Sass a danglam thei

Navbar zawng zawng tan variable awm thei:

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

Dark navbar atan hian variable hrang hrang : 1.1.

$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-dark-brand-color:           $navbar-dark-active-color;
$navbar-dark-brand-hover-color:     $navbar-dark-active-color;

Sass loop a ni

Responsive navbar expand/collapse class (eg, .navbar-expand-lg) te chu $breakpointsmap nen an inzawm khawm a, loop hmangin 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: var(--#{$prefix}navbar-nav-link-padding-x);
            padding-left: var(--#{$prefix}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 {
          // stylelint-disable declaration-no-important
          position: static;
          z-index: auto;
          flex-grow: 1;
          width: auto !important;
          height: auto !important;
          visibility: visible !important;
          background-color: transparent !important;
          border: 0 !important;
          transform: none !important;
          @include box-shadow(none);
          @include transition(none);
          // stylelint-enable declaration-no-important

          .offcanvas-header {
            display: none;
          }

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