in English

Navbar a ni

Bootstrap-a navigation header chak tak, chhanna pe thei, navbar atana documentation leh entirnan. Branding, navigation, collapse plugin leh a dangte support a keng 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}
  • Navbar leh a chhunga thil awmte hi default-in fluid a ni. An horizontal width tihtlem nan optional container hmang ang che .
  • 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.
  • Navbar te hi print laiin default in a thup thin. Print turin nawr luih tir la .d-print, .navbar. Display utility class chu en rawh .
  • 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"
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-inlineeng form control leh thiltih pawh atan.
  • .navbar-textthuziak vertically centered string dah belh nan.
  • .collapse.navbar-collapseparent breakpoint hmanga navbar contents group leh thup nan.

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.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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-toggle="dropdown" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

He entirnan hian color ( bg-light) leh spacing ( my-2, my-lg-0, mr-sm-0, my-sm-0) 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.

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

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

Image-a dah belh tur .navbar-brandchuan custom style emaw utilities emaw a mamawh reng mai thei a, chu chu a size dik tak a nih theih nan a ni. Entirnan entir tur thenkhat chu hetiang hi a ni.

<!-- Just an image -->
<nav class="navbar navbar-light bg-light">
  <a class="navbar-brand" href="#">
    <img src="/docs/4.6/assets/brand/bootstrap-solid.svg" width="30" height="30" alt="">
  </a>
</nav>
<!-- Image and text -->
<nav class="navbar navbar-light bg-light">
  <a class="navbar-brand" href="#">
    <img src="/docs/4.6/assets/brand/bootstrap-solid.svg" width="30" height="30" class="d-inline-block align-top" alt="">
    Bootstrap
  </a>
</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.

Active states—with .active—to indicate the current page chu .nav-links emaw an nu leh pa hnai ber s emaw hnenah direct-in hman theih a .nav-itemni.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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>
</nav>

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

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="nav-link" href="#">Features</a>
      <a class="nav-link" href="#">Pricing</a>
      <a class="nav-link disabled">Disabled</a>
    </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

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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-toggle="dropdown" aria-expanded="false">
          Dropdown link
        </a>
        <div class="dropdown-menu">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
    </ul>
  </div>
</nav>

Form hrang hrang

Navbar chhungah form control leh component hrang hrang dah la, .form-inline.

<nav class="navbar navbar-light bg-light">
  <form class="form-inline">
    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  </form>
</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 .

<nav class="navbar navbar-light bg-light">
  <a class="navbar-brand">Navbar</a>
  <form class="form-inline">
    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  </form>
</nav>

Input group te pawhin hna an thawk a:

<nav class="navbar navbar-light bg-light">
  <form class="form-inline">
    <div class="input-group">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon1">@</span>
      </div>
      <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 utilities hmangin element size hrang hrang align theih a nih thu pawh hriat nawn tirtu ropui tak a ni.

<nav class="navbar navbar-light bg-light">
  <form class="form-inline">
    <button class="btn btn-outline-success" 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.

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

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

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar w/ text</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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>
</nav>

Color scheme hrang hrang te

background-colorTheming class leh utilities te inzawmkhawm avang hian navbar theming hi a awlsam ngai lo . .navbar-lightBackground rawng eng tak tak nena hman tur, a nih loh leh background rawng dum nena hman tur atang hian thlang rawh .navbar-dark. .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 navbar-light" 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 bawk. 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.

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

.navbar-expand{-sm|-md|-lg|-xl}Container chu i navbar chhunga a awm chuan a horizontal padding chu i class tarlan aia breakpoint hniam zawkah a chhuak thin. Hei hian i navbar a collaps laiin lower viewport-ah a tul lo taka padding kan doubling lo tih a tichiang a ni.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container">
    <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, or stickied to the top atang hian thlang rawh (page chu a chung a thlen thlengin a scroll a, chutah chuan a awm reng ang). 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>

Tin , a .sticky-tophmang tih pawh hre bawk ang che position: sticky, chu chu browser tin ah a support kim lo .

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

Scroll a ni

Navbar collapsed-a toggleable contents chhunga vertical scrolling awm theihna .navbar-nav-scrollturin a .navbar-collapse(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 inline emaw custom style emaw hmangin i override thei thung. 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="max-height: 100px;", extra margin utility thenkhat nen optimum spacing atan kan rawn tarlang e.

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar scroll</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto my-2 my-lg-0 navbar-nav-scroll" style="max-height: 100px;">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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-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">
      <input class="form-control mr-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success" type="submit">Search</button>
    </form>
  </div>
</nav>

Chhanna pe thei nungchang

Navbars hian .navbar-toggler, .navbar-collapse, leh .navbar-expand{-sm|-md|-lg|-xl}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-expandNavbar collapse fo thin tan chuan class 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:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto mt-2 mt-lg-0">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

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

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto mt-2 mt-lg-0">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

Vei lamah toggler leh dinglamah brand name awmin:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto mt-2 mt-lg-0">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </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 thin .navbar. Kan plugin hian idand data-targetmatching ah hna a thawh avangin chu chu awlsam takin a ti thei!

<div class="fixed-top">
  <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">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
  </nav>
</div>

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.