Source

Navbar

Bootstrap-yň güýçli, täsirli nawigasiýa sözbaşy, deňiz paneli üçin resminamalar we mysallar. Marka, nawigasiýa we ş.m. goldawy, şol sanda ýykylýan pluginimize goldawy öz içine alýar.

Bu nähili işleýär

Deňiz paneli bilen başlamazdan ozal bilmeli zatlaryňyz:

  • Gämi duralgalary täsirli çökmek we reňk shemasy sapaklary üçin .navbarörtük talap edýär ..navbar-expand{-sm|-md|-lg|-xl}
  • Gämi duralgalary we olaryň mazmuny adaty ýagdaýda suwukdyr. Gorizontal giňligini çäklendirmek üçin goşmaça gaplary ulanyň .
  • Deňiz panelleriniň arasyndaky aralygy we deňleşmegi dolandyrmak üçin aralyk we flex peýdaly synplarymyzy ulanyň .
  • Gämi duralgalary adaty ýagdaýda jogap berýär, ýöne muny üýtgetmek üçin aňsatlyk bilen üýtgedip bilersiňiz. Jogapkärçilikli hereket, “Collapse JavaScript” pluginimize baglydyr.
  • Gämi duralgalary çap edilende asyl görnüşde gizlenýär. Goşmak arkaly olary çap .d-printetmäge mejbur ediň .navbar. Ekranyň peýdaly synpyna serediň .
  • Bir elementi ulanyp, elýeterliligi üpjün ediň <nav>ýa-da a ýaly has umumy elementi ulanýan bolsaňyz , kömekçi tehnologiýalary ulanýanlar üçin möhüm sebit hökmünde aç-açan kesgitlemek üçin her bir deňiz paneline <div>bir goşuň .role="navigation"

Mysal we goldanýan kiçi komponentleriň sanawyny okaň.

Goldanýan mazmun

Gämi duralgalary az sanly bölekler üçin içerki goldaw bilen gelýär. Zerur bolanda aşakdakylardan saýlaň:

  • .navbar-brandkompaniýaňyz, önümiňiz ýa-da taslama adyňyz üçin.
  • .navbar-navdoly beýik we ýeňil nawigasiýa üçin (aşak düşýänlere goldaw goşmak bilen).
  • .navbar-togglerýykylýan pluginimiz we beýleki nawigasiýa hereketlerini üýtgetmek üçin ulanmak üçin.
  • .form-inlineislendik görnüşdäki gözegçilik we hereketler üçin.
  • .navbar-textdikligine merkezleşdirilen tekstleri goşmak üçin.
  • .collapse.navbar-collapseene-atanyň nokady boýunça navbar mazmunyny toparlaşdyrmak we gizlemek üçin.

lgIne, (uly) kesiş nokadynda awtomatiki ýykylýan täsirli ýagtylyk temaly deňiz paneline girizilen ähli kiçi komponentleriň mysaly .

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

Bu mysalda reňk ( bg-light) we aralyk ( my-2,,, ) my-lg-0peýdaly synplar ulanylýar mr-sm-0.my-sm-0

Marka

Bu .navbar-brandelement köp elementlere ulanylyp bilner, ýöne labyr iň oňat işleýär, sebäbi käbir elementler peýdaly synplary ýa-da adaty stilleri talap edip biler.

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

Şekilleri islege goşmak, .navbar-brandelmydama dogry ölçeg üçin adaty stilleri ýa-da kömekçi enjamlary talap eder. Ine görkezmek üçin käbir mysallar.

<!-- 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 nawigasiýa baglanyşyklary .nav, öz üýtgediji synpy bilen opsiýalarymyzda gurulýar we dogry jogap bermek üçin açyk synplary ulanmagy talap edýär. Deňiz panellerinde nawigasiýa, deňiz paneliňiziň mazmunyny ygtybarly sazlamak üçin mümkin boldugyça gorizontal giňişligi eýelemek üçin öser .

Işjeň ýagdaýlar , häzirki sahypany göni ýa-da ýakyn ene-atalaryna .activeulanyp boljakdygyny görkezmek üçin ..nav-link.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>

Deňiz güýçlerimiz üçin sapaklary ulanýandygymyz sebäpli, isleseňiz sanaw esasly çemeleşmeden doly gaçyp bilersiňiz.

<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ýle hem, deňiz paneliňizdäki açylan ýerleri ulanyp bilersiňiz. Açylýan menýular ýerleşdirmek üçin örtük elementini talap edýär, şonuň üçin aşakda görkezilişi ýaly aýratyn .nav-itemwe ýerleşdirilen elementleri ulanmagy unutmaň..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="#" 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>

Formalar

Dürli forma dolandyryşlaryny we böleklerini deňiz panelinde ýerleşdiriň .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>

Içerki görnüşleriňiziň mazmunyny zerurlyk bilen kommunal hyzmatlar bilen deňleşdiriň.

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

Giriş toparlary hem işleýä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>

Bu düwme görnüşleriniň bir bölegi hökmünde dürli düwmeler hem goldanýar. Bu, wertikal deňleşdiriş enjamlarynyň dürli ululykdaky elementleri deňleşdirmek üçin ulanylyp bilinjekdigini hem ýatladýar.

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

Tekst

Gämi duralgalarynyň kömegi bilen bir topar tekst bolup biler .navbar-text. Bu synp tekstiň setirleri üçin dik tekizlemäni we keseligine aralygy sazlaýar.

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

Zerur bolanda beýleki komponentler we kömekçi enjamlar bilen garyşdyryň we gabat geliň.

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

Reňk shemalary

Deňiz panelini ýylatmak, mowzuk sapaklarynyň we kömekçi enjamlaryň utgaşmasy netijesinde hiç haçan aňsat bolmady background-color. .navbar-lightAçyk fon reňkleri ýa-da goýy fon reňkleri üçin saýlaň .navbar-dark. Soň bolsa, .bg-*kömekçi enjamlar bilen sazlaň.

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

Konteýnerler

Gerek däl bolsa-da, bir sahypany merkezleşdirmek üçin bir çyzgy paneli bilen örtüp ýa-da diňe kesgitli ýa-da statiki ýokarky deňiz paneliniň.container mazmunyny merkezleşdirmek üçin birine goşup bilersiňiz .

<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}Konteýner deňiz paneliňizde bolsa, gorizontal padding görkezilen synpyňyzdan pes nokatlarda aýrylýar . Deňiz paneli ýykylanda aşaky görnüşdäki ýerlere gereksiz ýerleşdirmekligi iki esse artdyrmaýarys.

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

Acementerleşiş

Deňiz panellerini statik däl ýerlerde ýerleşdirmek üçin pozisiýa hyzmatlarymyzy ulanyň . Fixedokardan ýokarsyna, aşagyna berkidilen ýa-da ýokarsyna berkidilenini saýlaň (sahypa ýokarsyna ýetýänçä aýlaň, soňra şol ýerde galar). Kesgitli gämi duralgalary ulanylýar position: fixed, ýagny DOM-yň adaty akymyndan çekilýär we beýleki elementler bilen gabat gelmezligi üçin ýörite CSS talap edip biler (mysal padding-topüçin ).<body>

Şeýle hem , her brauzerde doly goldanmaýan.sticky-top ulanylyşynaposition: sticky üns beriň .

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

Jogapkärçilikli özüni alyp baryş

Navbars mazmuny bir düwmäniň .navbar-toggleraňyrsynda ýykylanda üýtgäp biler. Beýleki kömekçi enjamlar bilen bilelikde belli elementleri haçan görkezmelidigini ýa-da gizlemelidigini aňsatlyk bilen saýlap bilersiňiz..navbar-collapse.navbar-expand{-sm|-md|-lg|-xl}

Hiç haçan ýykylmaýan gämi duralgalary üçin, deňiz paneline .navbar-expandsynp goşuň. Elmydama ýykylýan gämi duralgalary üçin hiç hili .navbar-expandsynp goşmaň.

Toggler

Navbar açarlary, adaty ýagdaýda çep hatara düzülendir, ýöne a ýaly dogan elementine eýerseler, .navbar-brandawtomatiki usulda sag tarapa deňleşerler. Belgiňizi yzyna öwürmek, geçirijiniň ýerleşdirilmegini tersleşdirer. Aşakda dürli üýtgetmek stilleriniň mysallary getirilýär.

.navbar-brandpes nokatda görkezilmedik:

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

Çepde görkezilen marka ady we sag tarapda üýtgetmek:

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

Çepde açar we sagda marka ady bilen:

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

Daşarky mazmun

Käwagt sahypanyň başga bir ýerinde gizlin mazmuny döretmek üçin çökmek plaginini ulanmak isleýärsiňiz. Plaginimiz gabat gelýän idwe data-targetişleýänligi sebäpli, aňsatlyk bilen ýerine ýetirilýär!

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