Esasy mazmuna geçiň Docs nawigasiýasyna geçiň
Check
in English

Deňiz we bellikler

“Bootstrap” -yň goşulan nawigasiýa komponentlerini nädip ulanmalydygy barada resminamalar we mysallar.

Esasy nav

.nav“Bootstrap” -da bar bolan nawigasiýa, esasy synpdan işjeň we maýyp ýagdaýlara çenli umumy bellikleri we stilleri paýlaşýar . Her stiliň arasynda geçmek üçin üýtgediji synplary çalyşyň.

Esasy .navkomponent flexbox bilen gurlup, ähli nawigasiýa komponentlerini gurmak üçin berk binýady üpjün edýär. Onda käbir stil ýazgylary (sanawlar bilen işlemek üçin), has uly urlan ýerler üçin käbir baglanyşyk paddingleri we esasy maýyp stilleri bar.

Esasy .navkomponent haýsydyr bir ýagdaýy öz içine almaýar .active. Aşakdaky mysallar, esasanam bu aýratyn synpyň hiç hili ýörite stil döretmeýändigini görkezmek üçin synpy öz içine alýar.

Işjeň ýagdaýy kömekçi tehnologiýalara ýetirmek üçin aria-currentatributdan peýdalanyň - häzirki sahypa ýa -da toplumdaky häzirki element üçin pagebahany ulanyň.true

html
<ul class="nav">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</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>

Sapaklar hemme ýerde ulanylýar, şonuň üçin belligiňiz gaty çeýe bolup biler. Harytlaryňyzyň tertibi möhüm bolsa, <ul>ýokardaky ýaly s ulanyň ýa-da bir element bilen özüňizi aýlaň. Ulanylyşy sebäpli , nav baglanyşyklary nav elementleri ýaly hereket edýär, ýöne goşmaça bellik bolmazdan.<ol><nav>.navdisplay: flex

html
<nav class="nav">
  <a class="nav-link active" aria-current="page" href="#">Active</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link disabled">Disabled</a>
</nav>

Elýeterli stiller

S komponentiniň stilini .navüýtgedijiler we kömekçi enjamlar bilen üýtgediň. Zerur bolanda garyşdyryň we deňeşdiriň ýa-da özüňiz guruň.

Gorizontal deňleşdirme

“Navbox” -yň gorizontal deňleşmesini “ flexbox” enjamlary bilen üýtgediň . Düzgüne görä, deňiz güýçleri çep hatara düzülendir, ýöne olary aňsatlyk bilen merkeze ýa-da sag tarapa üýtgedip bilersiňiz.

Merkezde .justify-content-center:

html
<ul class="nav justify-content-center">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</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>

Sag bilen deňleşdirilen .justify-content-end:

html
<ul class="nav justify-content-end">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</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>

Dik

Utgaşma bilen flex elementiň ugruny üýtgedip, nawigasiýaňyzy düzüň .flex-column. Olary käbir görnüşlerde ýerleşdirmeli, ýöne beýlekiler däl? Duýgur wersiýalary ulanyň (mysal üçin .flex-sm-column).

html
<ul class="nav flex-column">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</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>

Hemişe bolşy ýaly, wertikal nawigasiýa <ul>s bolmasa-da mümkindir.

html
<nav class="nav flex-column">
  <a class="nav-link active" aria-current="page" href="#">Active</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link disabled">Disabled</a>
</nav>

Salgylar

Esasy deňizden ýokardan alýar we goýlan .nav-tabsinterfeýs döretmek üçin synpy goşýar. JavaScript pluginimiz bilen tablisa sebitlerini döretmek üçin ulanyň .

html
<ul class="nav nav-tabs">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</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>

Dermanlar

Şol bir HTML alyň, ýöne .nav-pillsýerine ulanyň:

html
<ul class="nav nav-pills">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</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>

Doldur we akla

.navMazmunyňyzy iki üýtgediji synpyň biriniň elýeterli giňligini giňeltmäge mejbur ediň . Bar bolan ýerleri proporsional taýdan doldurmak üçin .nav-itemulanyň .nav-fill. Horhli gorizontal giňişligiň eýeleýändigine üns beriň, ýöne her bir deňiz elementiniň birmeňzeş giňligi ýok.

html
<ul class="nav nav-pills nav-fill">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Much longer nav link</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>

<nav>Esasy nawigasiýa ulanylanda, .nav-itemdiňe stil elementleri .nav-linküçin talap edilişi ýaly arkaýyn goýup bilersiňiz.<a>

html
<nav class="nav nav-pills nav-fill">
  <a class="nav-link active" aria-current="page" href="#">Active</a>
  <a class="nav-link" href="#">Much longer nav link</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link disabled">Disabled</a>
</nav>

Deň giňlikdäki elementler üçin ulanyň .nav-justified. Horhli gorizontal giňişlik deňiz baglanyşyklary bilen tutular, ýöne .nav-fillýokardakylardan tapawutlylykda her deňiz elementi birmeňzeş giňlikde bolar.

html
<ul class="nav nav-pills nav-justified">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Much longer nav link</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>

Esasy nawigasiýa .nav-fillulanmak mysalyna meňzeýär .<nav>

html
<nav class="nav nav-pills nav-justified">
  <a class="nav-link active" aria-current="page" href="#">Active</a>
  <a class="nav-link" href="#">Much longer nav link</a>
  <a class="nav-link" href="#">Link</a>
  <a class="nav-link disabled">Disabled</a>
</nav>

Flex kömekçi enjamlar bilen işlemek

Size jogap beriji üýtgeşiklikler gerek bolsa, flexbox kömekçi enjamlarynyň bir toparyny ulanmagy göz öňünde tutuň . Has köp sözli bolsa-da, bu kömekçi enjamlar jogap beriş nokatlarynda has uly özleşdirme hödürleýär. Aşakdaky mysalda, deňiz ýolumyz iň pes nokada ýerleşdiriler, soňra kiçi nokatdan başlap elýeterli giňligi doldurýan keseligine ýerleşer.

html
<nav class="nav nav-pills flex-column flex-sm-row">
  <a class="flex-sm-fill text-sm-center nav-link active" aria-current="page" href="#">Active</a>
  <a class="flex-sm-fill text-sm-center nav-link" href="#">Longer nav link</a>
  <a class="flex-sm-fill text-sm-center nav-link" href="#">Link</a>
  <a class="flex-sm-fill text-sm-center nav-link disabled">Disabled</a>
</nav>

Elýeterlilik barada

Nawigasiýa zolagyny üpjün etmek üçin deňiz güýçlerini ulanýan bolsaňyz role="navigation", iň logiki ene konteýnerine goşuň <ul>ýa-da <nav>tutuş nawigasiýa elementini gurşap alyň. Roly özüne goşmaň <ul>, sebäbi bu kömekçi tehnologiýalar arkaly hakyky sanaw hökmünde yglan edilmeginiň öňüni alar.

Nawigasiýa panelleriniň, hatda .nav-tabssynp bilen tablisa görnüşinde görnüp dursa-da, berilmeli däldigini ýarole="tablist" - role="tab"da role="tabpanel"atributlarynyň bolmaly däldigini unutmaň. Bular diňe ARIA Awtorlaşdyryş Amallary Gollanmasy tablisa görnüşinde beýan edilişi ýaly dinamiki goýlan interfeýsler üçin laýyk gelýär . Mysal üçin bu bölümdäki dinamiki goýlan interfeýsler üçin JavaScript häsiýetine serediň . Aýratynlyk dinamiki goýlan interfeýslerde hökmany däl, sebäbi JavaScript işjeň goýmany aria-currentgoşmak bilen saýlanan ýagdaýy dolandyrýar .aria-selected="true"

Açylýan ýerleri ulanmak

Birneme goşmaça HTML we açylan JavaScript plugin bilen açylýan menýulary goşuň .

Açylýan bellikler

html
<ul class="nav nav-tabs">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</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><a class="dropdown-item" href="#">Something else here</a></li>
      <li><hr class="dropdown-divider"></li>
      <li><a class="dropdown-item" href="#">Separated link</a></li>
    </ul>
  </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>

Açylýan dermanlar

html
<ul class="nav nav-pills">
  <li class="nav-item">
    <a class="nav-link active" aria-current="page" href="#">Active</a>
  </li>
  <li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</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><a class="dropdown-item" href="#">Something else here</a></li>
      <li><hr class="dropdown-divider"></li>
      <li><a class="dropdown-item" href="#">Separated link</a></li>
    </ul>
  </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>

CSS

Üýtgeýjiler

V5.2.0 goşuldy

“Bootstrap” -yň ösýän CSS üýtgeýjileriniň çemeleşmesiniň bir bölegi hökmünde, deňiz güýçleri häzirki wagtda ýerli CSS üýtgeýjileri ulanýarlar we hakyky .navwagtda özleşdirmek üçin. CSS üýtgeýjileriniň bahalary Sass arkaly kesgitlenýär, şonuň üçin Sass sazlamasy henizem goldanýar..nav-tabs.nav-pills

Esasy .navsynpda:

  --#{$prefix}nav-link-padding-x: #{$nav-link-padding-x};
  --#{$prefix}nav-link-padding-y: #{$nav-link-padding-y};
  @include rfs($nav-link-font-size, --#{$prefix}nav-link-font-size);
  --#{$prefix}nav-link-font-weight: #{$nav-link-font-weight};
  --#{$prefix}nav-link-color: #{$nav-link-color};
  --#{$prefix}nav-link-hover-color: #{$nav-link-hover-color};
  --#{$prefix}nav-link-disabled-color: #{$nav-link-disabled-color};
  

Üýtgediji .nav-tabssynpda:

  --#{$prefix}nav-tabs-border-width: #{$nav-tabs-border-width};
  --#{$prefix}nav-tabs-border-color: #{$nav-tabs-border-color};
  --#{$prefix}nav-tabs-border-radius: #{$nav-tabs-border-radius};
  --#{$prefix}nav-tabs-link-hover-border-color: #{$nav-tabs-link-hover-border-color};
  --#{$prefix}nav-tabs-link-active-color: #{$nav-tabs-link-active-color};
  --#{$prefix}nav-tabs-link-active-bg: #{$nav-tabs-link-active-bg};
  --#{$prefix}nav-tabs-link-active-border-color: #{$nav-tabs-link-active-border-color};
  

Üýtgediji .nav-pillssynpda:

  --#{$prefix}nav-pills-border-radius: #{$nav-pills-border-radius};
  --#{$prefix}nav-pills-link-active-color: #{$nav-pills-link-active-color};
  --#{$prefix}nav-pills-link-active-bg: #{$nav-pills-link-active-bg};
  

Sass üýtgeýjileri

$nav-link-padding-y:                .5rem;
$nav-link-padding-x:                1rem;
$nav-link-font-size:                null;
$nav-link-font-weight:              null;
$nav-link-color:                    var(--#{$prefix}link-color);
$nav-link-hover-color:              var(--#{$prefix}link-hover-color);
$nav-link-transition:               color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out;
$nav-link-disabled-color:           $gray-600;

$nav-tabs-border-color:             $gray-300;
$nav-tabs-border-width:             $border-width;
$nav-tabs-border-radius:            $border-radius;
$nav-tabs-link-hover-border-color:  $gray-200 $gray-200 $nav-tabs-border-color;
$nav-tabs-link-active-color:        $gray-700;
$nav-tabs-link-active-bg:           $body-bg;
$nav-tabs-link-active-border-color: $gray-300 $gray-300 $nav-tabs-link-active-bg;

$nav-pills-border-radius:           $border-radius;
$nav-pills-link-active-color:       $component-active-color;
$nav-pills-link-active-bg:          $component-active-bg;

JavaScript häsiýeti

bootstrap.jsJavaerli mazmunyň tablisa panellerini döretmek üçin nawigasiýa belliklerimizi we tabletkalarymyzy giňeltmek üçin JavaScript pluginini ulanyň - ony aýratyn ýa-da düzülen faýl arkaly goşuň.

Bu, Öý goýmasynyň baglanyşykly mazmuny. Başga bir düwmä bassaňyz, indiki üçin görnükliligini üýtgeder. JavaScript goýmasy, mazmunyň görünmegine we stiline gözegçilik etmek üçin sapaklary çalyşýar. Salgylar, dermanlar we beýleki .navgüýçli nawigasiýa bilen ulanyp bilersiňiz.

This is some placeholder content the Profile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Contact tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Disabled tab's associated content.

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home-tab-pane" type="button" role="tab" aria-controls="home-tab-pane" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile-tab-pane" type="button" role="tab" aria-controls="profile-tab-pane" aria-selected="false">Profile</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact-tab-pane" type="button" role="tab" aria-controls="contact-tab-pane" aria-selected="false">Contact</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="disabled-tab" data-bs-toggle="tab" data-bs-target="#disabled-tab-pane" type="button" role="tab" aria-controls="disabled-tab-pane" aria-selected="false" disabled>Disabled</button>
  </li>
</ul>
<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active" id="home-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="profile-tab-pane" role="tabpanel" aria-labelledby="profile-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="contact-tab-pane" role="tabpanel" aria-labelledby="contact-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="disabled-tab-pane" role="tabpanel" aria-labelledby="disabled-tab" tabindex="0">...</div>
</div>

Islegleriňize laýyk gelmek üçin, <ul>ýokarda görkezilişi ýaly esasly bellik bilen ýa-da islendik özbaşdak “özüňizi belläň” belligi bilen işleýär. Ulanylýan bolsaňyz <nav>, oňa gönüden-göni goşmaly däldigiňize üns beriň role="tablist", sebäbi bu elementiň nawigasiýa belligi hökmünde ýerli roluny ýok eder. Munuň ýerine alternatiw elemente geçiň (aşakdaky mysalda ýönekeý <div>) we <nav>daşyny gurşap alyň.

<nav>
  <div class="nav nav-tabs" id="nav-tab" role="tablist">
    <button class="nav-link active" id="nav-home-tab" data-bs-toggle="tab" data-bs-target="#nav-home" type="button" role="tab" aria-controls="nav-home" aria-selected="true">Home</button>
    <button class="nav-link" id="nav-profile-tab" data-bs-toggle="tab" data-bs-target="#nav-profile" type="button" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</button>
    <button class="nav-link" id="nav-contact-tab" data-bs-toggle="tab" data-bs-target="#nav-contact" type="button" role="tab" aria-controls="nav-contact" aria-selected="false">Contact</button>
    <button class="nav-link" id="nav-disabled-tab" data-bs-toggle="tab" data-bs-target="#nav-disabled" type="button" role="tab" aria-controls="nav-disabled" aria-selected="false" disabled>Disabled</button>
  </div>
</nav>
<div class="tab-content" id="nav-tabContent">
  <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="nav-disabled" role="tabpanel" aria-labelledby="nav-disabled-tab" tabindex="0">...</div>
</div>

Salgylar plugin hem dermanlar bilen işleýär.

Bu, Öý goýmasynyň baglanyşykly mazmuny. Başga bir düwmä bassaňyz, indiki üçin görnükliligini üýtgeder. JavaScript goýmasy, mazmunyň görünmegine we stiline gözegçilik etmek üçin sapaklary çalyşýar. Salgylar, dermanlar we beýleki .navgüýçli nawigasiýa bilen ulanyp bilersiňiz.

This is some placeholder content the Profile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Contact tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Disabled tab's associated content.

<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="pills-home-tab" data-bs-toggle="pill" data-bs-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="pills-profile-tab" data-bs-toggle="pill" data-bs-target="#pills-profile" type="button" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="pills-disabled-tab" data-bs-toggle="pill" data-bs-target="#pills-disabled" type="button" role="tab" aria-controls="pills-disabled" aria-selected="false" disabled>Disabled</button>
  </li>
</ul>
<div class="tab-content" id="pills-tabContent">
  <div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="pills-disabled" role="tabpanel" aria-labelledby="pills-disabled-tab" tabindex="0">...</div>
</div>

Wertikal dermanlar bilen. aria-orientation="vertical"Iň gowusy, wertikal bellikler üçin, tablisa sanawynyň konteýnerine hem goşmaly .

Bu, Öý goýmasynyň baglanyşykly mazmuny. Başga bir düwmä bassaňyz, indiki üçin görnükliligini üýtgeder. JavaScript goýmasy, mazmunyň görünmegine we stiline gözegçilik etmek üçin sapaklary çalyşýar. Salgylar, dermanlar we beýleki .navgüýçli nawigasiýa bilen ulanyp bilersiňiz.

This is some placeholder content the Profile tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Disabled tab's associated content.

This is some placeholder content the Messages tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

This is some placeholder content the Settings tab's associated content. Clicking another tab will toggle the visibility of this one for the next. The tab JavaScript swaps classes to control the content visibility and styling. You can use it with tabs, pills, and any other .nav-powered navigation.

<div class="d-flex align-items-start">
  <div class="nav flex-column nav-pills me-3" id="v-pills-tab" role="tablist" aria-orientation="vertical">
    <button class="nav-link active" id="v-pills-home-tab" data-bs-toggle="pill" data-bs-target="#v-pills-home" type="button" role="tab" aria-controls="v-pills-home" aria-selected="true">Home</button>
    <button class="nav-link" id="v-pills-profile-tab" data-bs-toggle="pill" data-bs-target="#v-pills-profile" type="button" role="tab" aria-controls="v-pills-profile" aria-selected="false">Profile</button>
    <button class="nav-link" id="v-pills-disabled-tab" data-bs-toggle="pill" data-bs-target="#v-pills-disabled" type="button" role="tab" aria-controls="v-pills-disabled" aria-selected="false" disabled>Disabled</button>
    <button class="nav-link" id="v-pills-messages-tab" data-bs-toggle="pill" data-bs-target="#v-pills-messages" type="button" role="tab" aria-controls="v-pills-messages" aria-selected="false">Messages</button>
    <button class="nav-link" id="v-pills-settings-tab" data-bs-toggle="pill" data-bs-target="#v-pills-settings" type="button" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</button>
  </div>
  <div class="tab-content" id="v-pills-tabContent">
    <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab" tabindex="0">...</div>
    <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab" tabindex="0">...</div>
    <div class="tab-pane fade" id="v-pills-disabled" role="tabpanel" aria-labelledby="v-pills-disabled-tab" tabindex="0">...</div>
    <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab" tabindex="0">...</div>
    <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab" tabindex="0">...</div>
  </div>
</div>

Elýeterlilik

ARIA Awtorlaşdyryş Amallary Gollanmasy tablisalarynda görkezilişi ýaly dinamiki bellikli interfeýsler, gurluşlaryny, işleýşini we häzirki ýagdaýyny kömekçi tehnologiýalary ulanyjylara (ekran okyjylary ýaly) ýetirmek üçin zerur we goşmaça atributlary talap edýär role="tablist". Iň oňat tejribe hökmünde, bellikler üçin elementleri ulanmagy maslahat berýäris , sebäbi bular täze sahypa ýa-da ýerleşişe däl-de, dinamiki üýtgeşmä itergi berýän dolandyryşlardyr.role="tab"role="tabpanel"aria-<button>

ARIA Awtorlaşdyryş amallary nagşyna laýyklykda diňe häzirki işjeň goýma klawiatura fokusyny alýar. JavaScript plugin işe girizilende tabindex="-1", ähli hereketsiz goýma dolandyryşlarynda gurlar. Häzirki işjeň goýmanyň ünsi jemlenenden soň, kursor düwmeleri öňki / indiki goýmany işjeňleşdirýär we plugin şoňa görä herekettabindex edýär . Şeýle-de bolsa, kursoryň esasy özara täsirleri barada aýdylanda, JavaScript plugininiň keseligine we dikligine tablisa sanawlaryny tapawutlandyrmaýandygyny belläň: tab sanawynyň ugruna garamazdan, ýokarky we çep kursor öňki tablisa, aşak we sag kursor gidýär. indiki goýma.

Umuman aýdanyňda, klawiatura nawigasiýasyny aňsatlaşdyrmak üçin, tab paneliniň içindäki manyly mazmuny öz içine alýan birinji element eýýäm ünsi jemlemese, tab panellerini hem ünsi jemlemek maslahat berilýär. JavaScript plugin bu tarapy çözmäge synanyşmaýar - zerur bolan ýagdaýynda, bellikleriňizi goşup, tab panelleriňizi aç-açan etmeli bolarsyňyz tabindex="0".
Salgy JavaScript plugin , açylýan menýulary öz içine alýan goýlan interfeýsleri goldamaýar , sebäbi bu ulanyş we elýeterlilik meselesini döredýär. Ulanyş nukdaýnazaryndan, häzirki görkezilen goýmanyň trigger elementiniň derrew görünmeýänligi (ýapyk açylan menýunyň içinde bolşy ýaly) bulaşyklyga sebäp bolup biler. Elýeterlilik nukdaýnazaryndan häzirki wagtda bu görnüşli gurluşy adaty WAI ARIA nagyşyna kartalaşdyrmagyň manyly usuly ýok, bu kömekçi tehnologiýalary ulanyjylara aňsatlyk bilen düşünip bolmaýar.

Maglumat atributlaryny ulanmak

data-bs-toggle="tab"Diňe bir elementi ýa-da bir elementi görkezip, hiç hili JavaScript ýazmazdan, tab ýa-da tablet nawigasiýasyny işjeňleşdirip bilersiňiz data-bs-toggle="pill". Bu maglumat atributlaryny ulanyň ýa- .nav-tabsda .nav-pills.

<!-- Nav tabs -->
<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="messages-tab" data-bs-toggle="tab" data-bs-target="#messages" type="button" role="tab" aria-controls="messages" aria-selected="false">Messages</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="settings-tab" data-bs-toggle="tab" data-bs-target="#settings" type="button" role="tab" aria-controls="settings" aria-selected="false">Settings</button>
  </li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab" tabindex="0">...</div>
  <div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab" tabindex="0">...</div>
  <div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab" tabindex="0">...</div>
  <div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab" tabindex="0">...</div>
</div>

JavaScript arkaly

JavaScript arkaly tablisa tablisalaryny açyň (her tab aýratynlykda işjeňleşdirilmeli):

const triggerTabList = document.querySelectorAll('#myTab button')
triggerTabList.forEach(triggerEl => {
  const tabTrigger = new bootstrap.Tab(triggerEl)

  triggerEl.addEventListener('click', event => {
    event.preventDefault()
    tabTrigger.show()
  })
})

Aýry-aýry bellikleri birnäçe usul bilen işjeňleşdirip bilersiňiz:

const triggerEl = document.querySelector('#myTab button[data-bs-target="#profile"]')
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name

const triggerFirstTabEl = document.querySelector('#myTab li:first-child button')
bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab

Öçürilen effekt

Salgylaryň ýitmegi .fadeüçin hersine goşuň .tab-pane. Ilkinji goýma paneli .showbaşlangyç mazmuny görünmeli.

<div class="tab-content">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="messages" role="tabpanel" aria-labelledby="messages-tab" tabindex="0">...</div>
  <div class="tab-pane fade" id="settings" role="tabpanel" aria-labelledby="settings-tab" tabindex="0">...</div>
</div>

Usullar

Asynkron usullar we geçişler

APIhli API usullary asynkron bolup, geçişe başlaýar . Geçiş başlan badyna, ýöne gutarmanka jaň edijä gaýdyp gelýärler . Mundan başga-da, geçiş komponentine çagyryş usuly hasaba alynmaz .

Has giňişleýin maglumat üçin JavaScript resminamalarymyza serediň .

Mazmunyňyzy goýma elementi hökmünde işjeňleşdirýär.

Konstruktor bilen bir tab mysal döredip bilersiňiz, mysal üçin:

const bsTab = new bootstrap.Tab('#myTab')
Usul Düşündiriş
dispose Bir elementiň goýmasyny ýok edýär.
getInstance DOM elementi bilen baglanyşykly tab mysalyny almaga mümkinçilik berýän statiki usul, ony şeýle ulanyp bilersiňiz : bootstrap.Tab.getInstance(element).
getOrCreateInstance DOM elementi bilen baglanyşykly tablisa mysalyny yzyna gaýtaryp berýän ýa-da başlamadyk ýagdaýynda täzesini döredýän statiki usul. Muny şeýle ulanyp bilersiňiz : bootstrap.Tab.getOrCreateInstance(element).
show Berlen goýmany saýlaýar we baglanyşykly paneli görkezýär. Öň saýlanan başga bir tab saýlanmaýar we oňa bagly panel gizlenýär. Salgy paneli hakykatdanam görkezilmänkä (ýagny shown.bs.tabwaka ýüze çykmazdan ozal) jaň edijä gaýdyp gelýär.

Wakalar

Täze tab görkezilende wakalar aşakdaky tertipde ýanýar:

  1. hide.bs.tab(häzirki işjeň goýmada)
  2. show.bs.tab(görkezilmeli goýmada)
  3. hidden.bs.tabhide.bs.tab(öňki işjeň goýmada, waka bilen birmeňzeş )
  4. shown.bs.tabshow.bs.tab(täze işjeň görkezilen ýaňy görkezilen goýmada, waka bilen birmeňzeş )

Hiç bir goýma eýýäm işjeň bolmadyk bolsa, wakalar hide.bs.tabwe hidden.bs.tabwakalar atylmaz.

Çäräniň görnüşi Düşündiriş
hide.bs.tab Bu waka täze goýma görkezilmeli bolanda ýanýar (we şeýlelik bilen öňki işjeň goýma gizlenmeli). Häzirki işjeň goýmany we ýakyn wagtda işjeň boljak täze goýmany ulanyň event.targetwe nyşana alyň.event.relatedTarget
hidden.bs.tab Bu waka täze goýma görkezilenden soň ýanýar (we şeýlelik bilen öňki işjeň goýma gizlenýär). Öňki işjeň goýmany we täze işjeň goýmany degişlilikde ulanyň event.targetwe nyşana alyň.event.relatedTarget
show.bs.tab Bu waka tab goýmasynda ýanýar, ýöne täze goýma görkezilmänkä. Işjeň goýmany we öňki işjeň goýmany degişlilikde ulanyň event.targetwe nyşana alyň.event.relatedTarget
shown.bs.tab Bu waka, görkezme görkezilenden soň tab goýmasynda ýanýar. Işjeň goýmany we öňki işjeň goýmany degişlilikde ulanyň event.targetwe nyşana alyň.event.relatedTarget
const tabEl = document.querySelector('button[data-bs-toggle="tab"]')
tabEl.addEventListener('shown.bs.tab', event => {
  event.target // newly activated tab
  event.relatedTarget // previous active tab
})