Source

Navbar

Akwụkwọ na ihe atụ maka isi igodo ụzọ Bootstrap na-anabata nke ọma, navbar. Gụnyere nkwado maka akara 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}na agba .
  • Navbars na ihe dị n'ime ha na-agbapụta na ndabara. Jiri igbe nhọrọ iji kpachie obosara ha kehoraizin.
  • 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.
  • A na-ezobe akwọ ụgbọ mmiri na ndabara mgbe a na-ebi akwụkwọ. Manye ka ebipụta ha site na ịgbakwunye .d-printna .navbar. Hụ klaasị ịba uru ngosi .
  • 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.

Gụkwuo maka ọmụmaatụ na ndepụta nke obere akụkụ akwadoro.

Ọ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ọ .
  • .form-inlinemaka njikwa na omume ụdị ọ bụla.
  • .navbar-textmaka ịgbakwunye eriri ederede kwụ n'etiti.
  • .collapse.navbar-collapsemaka ichikota na izobe ọdịnaya navbar site na ebe ezumike nne na nna.

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">
  <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="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <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" href="#">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>

Ọmụmaatụ a na-eji agba ( bg-light) na oghere ( my-2, my-lg-0, mr-sm-0) my-sm-0klaasị ịba uru.

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

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

Ịtinye onyonyo na nke ahụ .navbar-brandga-achọkarị ụdị omenala ma ọ bụ akụrụngwa iji nha nke ọma. Nke a bụ ihe atụ ụfọdụ iji gosi.

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

Njikọ igodo Navbar na-ewuli na .navnhọrọ anyị na klas modifier nke ha ma chọọ ka e jiri klaasị toggler maka nhazi nke ọma. Ntugharị n'ime ụgbọ mmiri 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.

Steeti na-arụsi ọrụ ike - na .active- iji gosi ibe dị ugbu a enwere ike itinye ya ozugbo na .nav-links ma ọ bụ nne na nna ha ozugbo .nav-item.

<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" href="#">Disabled</a>
      </li>
    </ul>
  </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">
  <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-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="nav-item nav-link" href="#">Features</a>
      <a class="nav-item nav-link" href="#">Pricing</a>
      <a class="nav-item nav-link disabled" href="#">Disabled</a>
    </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">
  <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="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown link
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <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>

Ụdị

Debe njikwa ụdị dị iche iche na akụrụngwa n'ime ụgbọ mmiri na .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>

Hazie ọdịnaya nke ụdị inline gị na akụrụngwa dị ka achọrọ.

<nav class="navbar navbar-light bg-light justify-content-between">
  <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>

Otu ntinye na-arụkwa ọrụ:

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

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

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">
  <span class="navbar-text">
    Navbar text with an inline element
  </span>
</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">
  <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>

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 ọ dịghị mkpa, ị nwere ike kechie a navbar na a .containerka etiti ya na ibe ma ọ bụ tinye otu n'ime naanị n'etiti ọdịnaya nke a ofu ma ọ bụ static top navbar .

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

Mgbe akpa ahụ dị n'ime ọdụ ụgbọ mmiri gị, a na-ewepụ padding ya kwụ ọtọ n'ebe nkwụsịtụ dị ala karịa .navbar-expand{-sm|-md|-lg|-xl}klaasị gị akọwapụtara. Nke a na-eme ka anyị hụ na anyị anaghị agbakọ okpukpu abụọ na padding na-enweghị isi na ọdụ ụgbọ elu dị ala mgbe ụgbọ mmiri gị daa.

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

Ndokwa

Jiri akụrụngwa ọnọdụ anyị tinye navbars n'ọnọdụ ndị 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">
  <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>

Àgwà na-anabata

Navbars nwere ike iji .navbar-toggler, .navbar-collapse, na .navbar-expand{-sm|-md|-lg|-xl}klaasị gbanwee 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.

Na-enweghị .navbar-brandegosiri na nkwụsịtụ kacha ala:

<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" href="#">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>

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

<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" href="#">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>

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

<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" href="#">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>

Ọdịnaya nke mpụga

Mgbe ụfọdụ, ịchọrọ iji ngwa mgbakwunye ọdịda iji kpalite ọdịnaya zoro ezo n'ebe ọzọ na ibe ahụ. N'ihi na ngwa mgbakwunye anyị na-arụ ọrụ idna data-targetmatching, nke ahụ dị mfe ime!

<div class="pos-f-t">
  <div class="collapse" id="navbarToggleExternalContent">
    <div class="bg-dark p-4">
      <h4 class="text-white">Collapsed content</h4>
      <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>