Source

Navbar

Mikanda mpe bandakisa mpo na motó ya botamboli ya nguya, ya eyano ya Bootstrap, navbar. Esangisi lisungi mpo na kosala marque, navigation, mpe mingi mosusu, bakisa mpe lisungi mpo na plugin na biso ya kokwea.

Ndenge oyo esalaka

Tala oyo esengeli oyeba liboso ya kobanda na navbar:

  • Navbars esengaka enveloppe .navbarna .navbar-expand{-sm|-md|-lg|-xl}pona ba classes ya collapsing responsive na scheme ya couleur .
  • Ba Navbars na ba contenus na yango eza fluide par défaut. Salelá ba récipients oyo okoki kopona mpo na kopekisa bonene na yango ya horizontal.
  • Salelá ba classes na biso ya espacement mpe flex utilitaire mpo na ko contrôler espacement mpe alignment na kati ya ba navbars.
  • Navbars ezali responsive par défaut, kasi okoki ko modifier yango facilement pona ko changer yango. Comportement ya réponse etali plugin na biso ya Collapse JavaScript.
  • Ba Navbars ebombamaka na ndenge ya libela ntango ya konyata. Na makasi ete bányata yango na kobakisáká .d-printna .navbar. Tala kelasi ya utilitaire ya kolakisa .
  • Kosala ete bozwi na kosalelaka <nav>eleman moko to, soki bosaleli eleman moko ya monene mingi lokola a <div>, bakisa a role="navigation"na navbar nyonso mpo na koyeba yango polele lokola etuka ya esika ya ntina mpo na basaleli ya mayele ya kosunga.

Effet ya animation ya composante oyo ezali dépendant na prefers-reduced-motionrequête ya média. Tala eteni ya mouvement réduit ya mikanda na biso ya accessibilité .

Tanga lisusu mpo na ndakisa mpe liste ya ba sous-composants oyo esungami.

Makambo oyo esungami

Navbars ezalaka na soutien intégré mpo na mwa ndambo ya ba sous-composants. Poná kati na makambo oyo elandi soki esengeli:

  • .navbar-brandmpo na kompanyi na yo, biloko na yo, to nkombo ya mosala na yo.
  • .navbar-navmpo na navigation ya bosanda mobimba mpe ya pete (na kati na yango lisungi mpo na ba dropdowns).
  • .navbar-togglermpo na kosalela na plugin na biso ya kokwea mpe bizaleli mosusu ya kobongola navigation .
  • .form-inlinempo na ba contrôles ya forme nionso mpe ba actions.
  • .navbar-textmpo na kobakisa bansinga ya makomi oyo ezali na katikati ya semba.
  • .collapse.navbar-collapsempo na kosangisa mpe kobomba makambo ya navbar na esika ya bopanzani ya moboti.

Tala ndakisa ya ba sous-composants nionso oyo ekotisami na navbar oyo ezo répondre na thème ya lumière oyo ezo collapser automatiquement na lgpoint de rupture (ya munene).

<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="#" tabindex="-1" aria-disabled="true">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>

Ndakisa oyo esaleli ba classes ya utilité ya couleur ( bg-light) na espacement ( my-2, my-lg-0, mr-sm-0, ).my-sm-0

Marke

The .navbar-brandekoki kosalelama na ba éléments mingi, kasi anchor esalaka malamu lokola ba éléments mosusu ekoki kosenga ba classes ya utilité to ba styles personnalisés.

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

Kobakisa bililingi na .navbar-brandekosɛnga mbala mosusu ntango nyonso ba styles to ba utilitaires personnalisés mpo na bonene oyo ebongi. Talá mwa bandakisa oyo tokoki komonisa.

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

Ba liens ya navigation ya Navbar etongami na ba .navoptions na biso na classe na bango moko ya modificateur mpe esengaka kosalela ba classes ya toggler mpo na styling ya réponse ya malamu. Navigation na ba navbars ekokola pe pona ko occuper espace horizontal ebele ndenge ekoki pona ko garder ba contenus ya navbar na yo na sécurité aligné.

Ba états .activeactifs —na —mpo na kolakisa lokasa ya lelo ekoki kosalelama mbala moko na .nav-links to baboti na bango ya penepene .nav-items.

<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="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </li>
    </ul>
  </div>
</nav>

Et po tosalelaka ba classes pona ba navs na biso, okoki ko éviter approche basé na liste entièrement soki olingi.

<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="#" tabindex="-1" aria-disabled="true">Disabled</a>
    </div>
  </div>
</nav>

Okoki mpe kosalela ba dropdowns na navbar nav na yo. Ba menu ya kokita esengaka élément ya enveloppe mpo na positionnement, yango wana sala makasi osalela ba éléments separates mpe encastrés mpo na .nav-itemmpe .nav-linkndenge elakisami awa na se.

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

Baformilɛrɛ

Tia ba contrôles ya formulaire ndenge na ndenge na ba composants na kati ya navbar 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>

Bana ya mbala moko ba éléments na .navbarusage flex layout mpe ekozala par défaut na justify-content: between. Salelá ba utilitaires flex ya kobakisa soki esengeli mpo na kobongisa bizaleli oyo.

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

Ba groupes ya entrée esalaka, pe:

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

Ba boutons ndenge na ndenge esungami lokola eteni ya ba formulaire oyo ya navbar, mpe. Oyo ezali mpe bokundoli monene ete ba utilitaires ya alignment vertical ekoki kosalelama mpo na ko aligner ba éléments ya taille différente.

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

Nkoma

Navbars ekoki kozala na biteni ya makomi na lisalisi ya .navbar-text. Kelasi oyo ebongisaka alignment vertical mpe espacement horizontal mpo na ba chaînes ya texte.

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

Sangisa mpe kosangisa na ba composants mpe ba utilités mosusu soki esengeli.

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

Ba schemes ya ba couleurs

Thème ya navbar ezalaki jamais facile grâce na combinaison ya ba classes ya thème na ba background-colorutilitaires. Pona kati na yango .navbar-lightmpo na kosalela yango na balangi ya nsima ya pole, to .navbar-darkmpo na balangi ya nsima ya moindo. Na nsima, personnaliser na ba .bg-*utilités.

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

Ba récipients

Atako esengeli te, okoki kozinga navbar na a .containermpo na kotya yango na katikati na lokasa to kobakisa moko na kati mpo na kotya kaka na katikati ya makambo ya navbar ya likoló oyo etɛngamá te to oyo ezali kotɛngatɛnga te .

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

Tango conteneur ezali na kati ya navbar na yo, remplissage horizontal na yango elongolamaka na ba points de rupture na se ya .navbar-expand{-sm|-md|-lg|-xl}classe na yo oyo olakisaki. Yango ezali kosala ete tozali te ko doubler likolo na padding na ntina te na ba viewports ya nse ntango navbar na yo ezali kokweya.

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

Botiami na esika

Salelá ba utilitaires na biso ya position mpo na kotia ba navbars na ba positions oyo ezali statique te. Poná kati na oyo ekangami na likoló, ekangami na nse, to ekangami na likoló (kosala défilement na lokasa tii ekokóma na likoló, na nsima etikalaka wana). Ba navbars fixes esalela position: fixed, elingi koloba ba bendami na flux normal ya DOM mpe ekoki kosenga CSS personnalisé (ndakisa, padding-topna <body>) mpo na kopekisa superposition na ba éléments mosusu.

Yeba mpe ete .sticky-topesalela position: sticky, oyo esimbami mobimba te na navigateur nyonso .

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

Bizaleli ya koyanola

Navbars ekoki kosalela .navbar-toggler, .navbar-collapse, mpe .navbar-expand{-sm|-md|-lg|-xl}bakelasi mpo na kobongwana ntango makambo na yango ekwei nsima ya bouton moko. Na kosangisa na ba utilitaires mosusu, okoki kopona na pete tango nini kolakisa to kobomba ba éléments particuliers.

Mpo na ba navbar oyo ekweaka ata moke te, bakisa .navbar-expandkelasi na navbar. Pona ba navbars oyo ezo collapser toujours, kobakisa .navbar-expandclasse moko te.

Moto oyo azali kobongola makambo

Ba togglers ya Navbar ezali na gauche-aligné par défaut, kasi soki balandi élément ya ndeko lokola .navbar-brand, bakozala automatiquement aligné na extreme droite. Kozongisa sima marquage na yo ekozongisa sima placement ya toggler. Awa na se ezali na bandakisa ya ba styles ya toggle ekeseni.

Na moko te .navbar-brandelakisami na point de rupture ya nse:

<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="#" tabindex="-1" aria-disabled="true">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>

Na kombo ya marque oyo elakisami na gauche mpe toggler na droite:

<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="#" tabindex="-1" aria-disabled="true">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>

Na toggler na gauche mpe kombo ya marque na droite:

<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="#" tabindex="-1" aria-disabled="true">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>

Makambo ya libanda

Tango mosusu olingi kosalela plugin ya collapse mpo na ko déclencher ba contenus oyo ebombami esika mosusu na page. Po plugin na biso esalaka na idpe data-targetmatching, yango esalemaka facilement!

<div class="pos-f-t">
  <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>