Source

Navbar

Fa'amaumauga ma fa'ata'ita'iga mo le fa'auluuluga fa'atonu mamana a Bootstrap, le navbar. E aofia ai le lagolago mo le fa'ailogaina, fa'atautaiga, ma isi mea, e aofia ai le lagolago mo la tatou fa'apalapala pa'u.

E faapefea ona galue

O mea nei e tatau ona e iloa ae e te leʻi amataina le navbar:

  • Navbars e manaʻomia se afifiina mo vasega pa'u ma .navbarlanu lanu ..navbar-expand{-sm|-md|-lg|-xl}
  • Navbars ma a latou mea o loʻo i totonu o loʻo faʻafefe ona o le faaletonu. Fa'aoga koneteina e filifili ai e fa'atapula'a le lautele fa'alava.
  • Fa'aoga a matou va'aiga ma fetu'utu'una'i vasega aoga mo le fa'atonutonuina o le va ma le fa'aogaina i totonu o navbars.
  • Navbars e tali mai e ala i le le mafai, ae e faigofie ona e suia e sui ai lena mea. O amioga tali atu e fa'alagolago i la matou Collapse JavaScript plugin.
  • Navbars e natia e ala i le faaletonu pe a lolomi. Faamalosia e lolomi e ala i le faaopoopo .d-printi le .navbar. Va'ai le vasega fa'aaliga aoga.
  • Fa'amautinoa le fa'aogaina e ala i le fa'aogaina o se <nav>elemene po'o, pe a fa'aaogaina se elemene e sili atu le lautele e pei o le <div>, fa'aopoopo se role="navigation"i luga ole navbar uma e fa'ailoa manino ai o se fa'ailoga mata'ina mo tagata fa'aoga tekinolosi fesoasoani.

Faitau mo se faʻataʻitaʻiga ma se lisi o vaega laiti lagolago.

Mea e lagolagoina

Navbars e sau ma faʻapipiʻi i totonu o le lagolago mo ni nai vaega laiti. Filifili mai mea nei pe a manaʻomia:

  • .navbar-brandmo lau kamupani, oloa, po'o le igoa ole poloketi.
  • .navbar-navmo se folauga maualuga ma mama (e aofia ai le lagolago mo pa'u i lalo).
  • .navbar-togglermo le fa'aoga i la matou fa'apalapala pa'u ma isi fa'asologa aga fa'asolo .
  • .form-inlinemo so'o se fomu fa'atonuga ma gaioiga.
  • .navbar-textmo le fa'aopoopoina o laina fa'aogatotonu i luga o le sa'o o tusitusiga.
  • .collapse.navbar-collapsemo le fa'avasegaina ma le nanaina o mea o lo'o i totonu o le navbar e ala i se va'aiga matua.

O se fa'ata'ita'iga lea o vaega laiti uma o lo'o aofia i totonu o se navbar e fa'atatau i le malamalama e otometi lava ona pa'u ile lg(tele) malepe.

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

O lenei fa'ata'ita'iga e fa'aaoga ai le lanu ( bg-light) ma le va ( ,,, ) vasega aoga .my-2my-lg-0mr-sm-0my-sm-0

Fa'ailoga

E .navbar-brandmafai ona fa'aoga i le tele o elemene, ae o se taula e sili ona aoga ona o nisi elemene e ono mana'omia ai vasega aoga po'o sitaili masani.

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

O le fa'aopoopoina o ata i le ata e .navbar-brandono mana'omia ai sitaili fa'aaganu'u po'o mea fa'aoga i le lapopoa sa'o. O nisi nei o faʻataʻitaʻiga e faʻaalia.

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

Navbar navigation links e fausia i luga oa tatou .navfilifiliga ma a latou lava vasega faʻaleleia ma manaʻomia le faʻaogaina o vasega toggler mo le faʻaogaina talafeagai. O le a fa'atupula'ia fo'i le fa'atauta'iga i luga ole laiga e nofoia le tele o avanoa fa'ata'amilo e mafai ai ona fa'atutu lelei lau fa'aoga o le navbar.

Active states-with .active-e faʻaalia ai le itulau o loʻo iai nei e mafai ona faʻaoga saʻo i .nav-links poʻo latou matua matua .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 talu ai matou te faʻaogaina vasega mo a matou navs, e mafai ona e aloese mai le faʻaogaina o le lisi atoa pe a e fiafia i ai.

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

E mafai fo'i ona e fa'aogaina fa'alalo i lau navbar nav. E mana'omia e menus dropdown se elemene afifi mo le fa'atulagaina, ia mautinoa e fa'aaoga elemene eseese ma fa'aputu mo .nav-itemma .nav-linkpei ona fa'aalia i lalo.

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

Fomu

Tu'u ni fa'atonuga eseese ma vaega i totonu o se navbar ma .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>

Fa'afetaui mea o lo'o i totonu o au fomu fa'asinomaga ma mea aoga pe a mana'omia.

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

E galue fo'i vaega fa'aoga:

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

O fa'amau eseese o lo'o lagolagoina o se vaega o nei fomu navbar, fo'i. Ose fa'amanatu sili foi lea e mafai ona fa'aoga mea fa'aoga fa'atutusa e fa'aoga ai elemene eseese.

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

Tusitusi

Navbars e mafai ona i ai ni vaega o tusitusiga ma le fesoasoani a .navbar-text. O lenei vasega e fetu'una'i le fa'asolo i luga ma le avanoa fa'alava mo manoa o tusitusiga.

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

Faafefiloi ma fetaui ma isi vaega ma mea aoga pe a manaʻomia.

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

Fa'ailoga lanu

O le faʻaogaina o le navbar e leʻi faigofie lava faʻafetai i le tuʻufaʻatasia o vasega autu ma background-colormea aoga. Filifili mai .navbar-lightmo le fa'aoga i lanu malamalama i tua, pe .navbar-darkmo lanu pogisa. Ona, faʻavasegaina ma .bg-*mea faʻaoga.

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

Koneteina

E ui lava e le manaʻomia, e mafai ona e afifiina se navbar i totonu .containere faʻatotonugalemu i luga o se itulau pe faʻaopoopo se tasi i totonu e naʻo totonugalemu o mea o loʻo i totonu o se faʻamaufaʻailoga pito i luga navbar .

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

A o'o le koneteina i totonu o lau navbar, e 'ave'esea lona fa'alava fa'alava ile va'a maualalo ifo nai lo lau .navbar-expand{-sm|-md|-lg|-xl}vasega fa'apitoa. Ole mea lea e fa'amautinoa ai tatou te le fa'aluaina le fa'aofuofu fa'aletonu ile va'aiga pito i lalo pe a pa'u lau navbar.

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

Tulaga

Fa'aoga a matou tulaga fa'aoga e tu'u ai navbars i tulaga e le fa'amautu. Filifili mai le fa'amau i le pito i luga, fa'amau i lalo, po'o le pipii i le pito i luga (ta'ai ma le itulau se'ia o'o i le pito i luga, ona nofo ai lea iina). Fa'aoga navbars fa'amaumau position: fixed, o lona uiga e toso mai le tafe masani a le DOM ma e ono mana'omia le CSS masani (fa'ata'ita'iga, padding-topi luga o le <body>) e puipuia ai le sosolo ma isi elemene.

Ia maitauina foi o le .sticky-topfa'aoga position: sticky, lea e le'o lagolagoina atoatoa i so'o se su'esu'ega .

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

Amioga tali atu

E mafai e Navbars ona fa'aoga .navbar-toggler, .navbar-collapse, ma .navbar-expand{-sm|-md|-lg|-xl}vasega e sui pe a pa'u a latou mea i tua o se ki. Faʻatasi ma isi faʻaoga, e faigofie ona e filifilia le taimi e faʻaalia pe nana ai elemene faapitoa.

Mo navbars e le mafai ona pa'u, fa'aopoopo le .navbar-expandvasega ile navbar. Mo navbars e pa'u i taimi uma, aua le fa'aopoopoina se .navbar-expandvasega.

Toggler

Navbar togglers o lo'o fa'aoga agavale ona o le fa'aletonu, ae afai latou te mulimuli i se uso e pei o le .navbar-brand, o le a otometi lava ona fa'aoga i le itu taumatau. O le toe fesuia'i o lau fa'ailoga o le a toe fa'afo'i ai le tu'uga o le koli. O lo'o i lalo ni fa'ata'ita'iga o sitaili fe'avea'i eseese.

E aunoa ma se .navbar-brandfa'aalia i le pito maualalo:

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

Faatasi ai ma se igoa faʻailoga o loʻo faʻaalia i le agavale ma le toggle i le taumatau:

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

Faatasi ai ma se koli i le agavale ma le igoa fa'ailoga i le taumatau:

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

Anotusi fafo

O nisi taimi e te mana'o ai e fa'aoga le pa'u pa'u e fa'aoso ai mea natia i se isi mea i luga o le itulau. Ona o le matou plugin e galue i luga o le idma data-targetfetaui, e faigofie lava ona fai!

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