Ruka hadi kwa yaliyomo kuu Ruka hadi kwenye urambazaji wa hati
Check
in English

Navs na tabo

Nyaraka na mifano ya jinsi ya kutumia vipengee vya urambazaji vilivyojumuishwa vya Bootstrap.

Nav ya msingi

Urambazaji unapatikana katika muundo na mitindo ya jumla ya kushiriki Bootstrap, kutoka .navdarasa la msingi hadi majimbo amilifu na ya walemavu. Badilisha madarasa ya kurekebisha ili kubadili kati ya kila mtindo.

Sehemu ya msingi .navimejengwa kwa flexbox na kutoa msingi imara wa kujenga aina zote za vipengele vya urambazaji. Inajumuisha ubatilishaji wa mitindo fulani (ya kufanya kazi na orodha), baadhi ya miunganisho ya viungo kwa maeneo makubwa zaidi, na mitindo ya kimsingi iliyozimwa.

Sehemu ya msingi .navhaijumuishi .activejimbo lolote. Mifano ifuatayo ni pamoja na darasa, haswa ili kuonyesha kuwa darasa hili halichochei mtindo wowote maalum.

Ili kuwasilisha hali amilifu kwa teknolojia saidizi, tumia aria-currentsifa - kwa kutumia pagethamani ya ukurasa wa sasa, au truekwa kipengee cha sasa katika seti.

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>

Madarasa hutumiwa kote, kwa hivyo lebo yako inaweza kunyumbulika sana. Tumia <ul>s kama ilivyo hapo juu, <ol>ikiwa mpangilio wa vitu vyako ni muhimu, au pindua yako na <nav>kipengee. Kwa sababu .navmatumizi display: flex, viungo vya nav hufanya kazi sawa na vipengee vya nav, lakini bila ghafi ya ziada.

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>

Mitindo inayopatikana

Badilisha mtindo wa .navsehemu ya s na virekebishaji na huduma. Changanya na ulinganishe inavyohitajika, au ujenge yako mwenyewe.

Mpangilio wa mlalo

Badilisha mpangilio mlalo wa nav yako na huduma za flexbox . Kwa chaguo-msingi, navs zimepangiliwa kushoto, lakini unaweza kuzibadilisha kwa urahisi hadi zikiwa zimepangiliwa katikati au kulia.

Iliyowekwa katikati na .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>

Inayolingana na .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>

Wima

Ratibu urambazaji wako kwa kubadilisha mwelekeo wa kipengee rahisi na .flex-columnmatumizi. Je! unahitaji kuziweka kwenye tovuti zingine za kutazama lakini sio zingine? Tumia matoleo sikivu (kwa mfano, .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>

Kama kawaida, urambazaji wima unawezekana bila <ul>s, pia.

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>

Vichupo

Huchukua nav ya msingi kutoka juu na kuongeza .nav-tabsdarasa ili kutoa kiolesura chenye kichupo. Zitumie kuunda maeneo yanayoweza kutekelezeka na kichupo chetu cha programu jalizi ya JavaScript .

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>

Vidonge

Chukua HTML hiyo hiyo, lakini tumia .nav-pillsbadala yake:

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>

Jaza na uhalalishe

Lazimisha .navyaliyomo yako kupanua upana kamili unaopatikana moja ya aina mbili za kirekebishaji. Ili kujaza nafasi zote zinazopatikana kwa uwiano .nav-item, tumia .nav-fill. Tambua kuwa nafasi yote ya mlalo imekaliwa, lakini si kila kipengee cha nav kina upana sawa.

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>

Unapotumia <nav>urambazaji unaotegemea, unaweza kuacha kwa usalama .nav-itemkama .nav-linkinavyohitajika tu kwa <a>vipengele vya kupiga maridadi.

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>

Kwa vipengele vya upana sawa, tumia .nav-justified. Nafasi yote ya mlalo itakaliwa na viungo vya nav, lakini tofauti na ilivyo .nav-fillhapo juu, kila kipengee cha nav kitakuwa na upana sawa.

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>

Sawa na .nav-fillmfano kutumia <nav>urambazaji-msingi.

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>

Kufanya kazi na huduma za kubadilika

Ikiwa unahitaji tofauti za nav zinazojibu, zingatia kutumia mfululizo wa huduma za flexbox . Ingawa ni ya kitenzi zaidi, huduma hizi hutoa ubinafsishaji zaidi katika sehemu zote za kujibu. Katika mfano ulio hapa chini, nav yetu itapangwa kwenye sehemu ya chini kabisa ya kukatika, kisha itengeneze kwa mpangilio mlalo unaojaza upana unaopatikana kuanzia sehemu ndogo ya kukatika.

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>

Kuhusu ufikivu

Ikiwa unatumia navs kutoa upau wa kusogeza, hakikisha kuwa umeongeza kwenye role="navigation"kontena kuu la kimantiki zaidi la <ul>, au funika <nav>kipengee kwenye usogezaji wote. Usiongeze jukumu kwenye <ul>yenyewe, kwani hii inaweza kuizuia kutangazwa kama orodha halisi na teknolojia saidizi.

Kumbuka kuwa pau za kusogeza, hata zikiwekwa mtindo wa kuonekana kama vichupo na .nav-tabsdarasa, hazipaswi kupewa , role="tablist"au role="tab"sifa role="tabpanel". Hizi zinafaa tu kwa violesura vinavyobadilika vya vichupo, kama ilivyofafanuliwa katika muundo wa vichupo vya Mwongozo wa Mazoea ya Uandishi wa ARIA . Tazama tabia ya JavaScript kwa violesura vinavyobadilika vya vichupo katika sehemu hii kwa mfano. Sifa aria-currentsi muhimu kwenye violesura vinavyobadilika vya vichupo kwa kuwa JavaScript yetu hushughulikia hali iliyochaguliwa kwa kuongeza aria-selected="true"kwenye kichupo kinachotumika.

Kwa kutumia menyu kunjuzi

Ongeza menyu kunjuzi na HTML ya ziada kidogo na programu- jalizi ya JavaScript .

Vichupo vilivyo na menyu kunjuzi

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>

Vidonge vilivyo na kushuka

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

Vigezo

Imeongezwa katika v5.2.0

Kama sehemu ya mbinu ya mabadiliko ya vigeu vya CSS ya Bootstrap, navs sasa hutumia viwezo vya ndani vya CSS kwenye .nav, .nav-tabs, na .nav-pillskwa uboreshaji wa ubinafsishaji wa wakati halisi. Thamani za anuwai za CSS zimewekwa kupitia Sass, kwa hivyo ubinafsishaji wa Sass bado unatumika, pia.

Kwenye .navdarasa la msingi:

  --#{$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};
  

Kwenye .nav-tabsdarasa la kurekebisha:

  --#{$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};
  

Kwenye .nav-pillsdarasa la kurekebisha:

  --#{$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};
  

Vigezo vya Sass

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

Tabia ya JavaScript

Tumia kichupo cha programu-jalizi ya JavaScript—ijumuishe kibinafsi au kupitia faili iliyokusanywa bootstrap.js—ili kupanua vichupo vyetu vya kusogeza na vidonge ili kuunda vidirisha vinavyoweza kutekelezeka vya maudhui ya ndani.

Haya ni baadhi ya maudhui ya kishika nafasi maudhui yanayohusiana na kichupo cha Nyumbani . Kubofya kichupo kingine kutageuza mwonekano wa hiki kwa kinachofuata. Kichupo cha JavaScript hubadilishana madarasa ili kudhibiti mwonekano wa maudhui na mitindo. Unaweza kuitumia pamoja na vichupo, tembe, na .navurambazaji mwingine wowote unaotumia nguvu.

Haya ni baadhi ya maudhui ya kishikilia nafasi maudhui yanayohusiana na kichupo cha Wasifu . Kubofya kichupo kingine kutageuza mwonekano wa hiki kwa kinachofuata. Kichupo cha JavaScript hubadilishana madarasa ili kudhibiti mwonekano wa maudhui na mitindo. Unaweza kuitumia pamoja na vichupo, tembe, na .navurambazaji mwingine wowote unaotumia nguvu.

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>

Ili kukusaidia kutosheleza mahitaji yako, hii inafanya kazi na <ul>alama-msingi, kama inavyoonyeshwa hapo juu, au kwa lebo yoyote ya kiholela ya "weka yako mwenyewe". Kumbuka kuwa ikiwa unatumia <nav>, hupaswi kuiongeza role="tablist"moja kwa moja, kwani hii ingebatilisha jukumu asili la kipengele kama alama muhimu ya urambazaji. Badala yake, badilisha kwa kipengee mbadala (katika mfano hapa chini, rahisi <div>) na uifunge <nav>kuzunguka.

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

Programu-jalizi ya tabo pia inafanya kazi na vidonge.

Haya ni baadhi ya maudhui ya kishika nafasi maudhui yanayohusiana na kichupo cha Nyumbani . Kubofya kichupo kingine kutageuza mwonekano wa hiki kwa kinachofuata. Kichupo cha JavaScript hubadilishana madarasa ili kudhibiti mwonekano wa maudhui na mitindo. Unaweza kuitumia pamoja na vichupo, tembe, na .navurambazaji mwingine wowote unaotumia nguvu.

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>

Na kwa vidonge vya wima. Kwa hakika, kwa vichupo vya wima, unapaswa pia kuongeza aria-orientation="vertical"kwenye kontena la orodha ya kichupo.

Haya ni baadhi ya maudhui ya kishika nafasi maudhui yanayohusiana na kichupo cha Nyumbani . Kubofya kichupo kingine kutageuza mwonekano wa hiki kwa kinachofuata. Kichupo cha JavaScript hubadilishana madarasa ili kudhibiti mwonekano wa maudhui na mitindo. Unaweza kuitumia pamoja na vichupo, tembe, na .navurambazaji mwingine wowote unaotumia nguvu.

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>

Ufikivu

Violesura vyenye vichupo vinavyobadilika, kama ilivyofafanuliwa katika muundo wa vichupo vya Mwongozo wa Mazoezi ya Uandishi wa ARIA , huhitaji role="tablist", role="tab", role="tabpanel", na sifa za ziada aria-ili kuwasilisha muundo, utendakazi na hali ya sasa kwa watumiaji wa teknolojia saidizi (kama vile visoma skrini). Kama mbinu bora, tunapendekeza kutumia <button>vipengele vya vichupo, kwa kuwa hivi ni vidhibiti vinavyoanzisha mabadiliko yanayobadilika, badala ya viungo vinavyoelekeza kwenye ukurasa mpya au eneo.

Sambamba na mchoro wa Mazoezi ya Uandishi wa ARIA, kichupo kinachotumika sasa pekee ndicho hupokea ulengaji wa kibodi. Wakati programu-jalizi ya JavaScript imeanzishwa, itawekwa tabindex="-1"kwenye vidhibiti vyote vya vichupo visivyotumika. Pindi kichupo kinachotumika sasa kinapozingatia, vitufe vya kishale huwasha kichupo kilichotangulia/kifuatacho, huku programu-jalizi ikibadilisha rovingtabindex ipasavyo. Walakini, kumbuka kuwa programu-jalizi ya JavaScript haitofautishi kati ya orodha za vichupo vya mlalo na wima linapokuja suala la mwingiliano wa vitufe vya kishale: bila kujali mwelekeo wa orodha ya kichupo, kishale cha juu na kushoto huenda kwenye kichupo kilichotangulia, na kishale cha chini na kulia huenda kwa kichupo kinachofuata.

Kwa ujumla, ili kuwezesha urambazaji wa kibodi, inashauriwa kufanya vidirisha vya vichupo vyenyewe kuangaziwa pia, isipokuwa kipengele cha kwanza kilicho na maudhui muhimu ndani ya kidirisha cha kichupo tayari kinaweza kuangaziwa. Programu-jalizi ya JavaScript haijaribu kushughulikia kipengele hiki—inapofaa, utahitaji kwa uwazi kufanya vidirisha vya vichupo vyako kuangaziwa kwa kuongeza tabindex="0"katika lebo yako.
Kichupo cha programu jalizi ya JavaScript hakitumii violesura vilivyo na vichupo ambavyo vina menyu kunjuzi, kwa kuwa hizi husababisha masuala ya utumiaji na ufikivu. Kwa mtazamo wa utumiaji, ukweli kwamba kichochezi cha kichupo kinachoonyeshwa kwa sasa hakionekani mara moja (kwani kiko ndani ya menyu kunjuzi iliyofungwa) inaweza kusababisha mkanganyiko. Kwa mtazamo wa ufikivu, kwa sasa hakuna njia ya busara ya kupanga aina hii ya muundo kwa muundo wa kawaida wa WAI ARIA, kumaanisha kuwa haiwezi kueleweka kwa urahisi kwa watumiaji wa teknolojia saidizi.

Kutumia sifa za data

Unaweza kuwezesha urambazaji wa kichupo au kidonge bila kuandika JavaScript yoyote kwa kubainisha data-bs-toggle="tab"au data-bs-toggle="pill"kwa kipengee. Tumia sifa hizi za data kwenye .nav-tabsau .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>

Kupitia JavaScript

Washa vichupo vinavyoweza kutekelezeka kupitia JavaScript (kila kichupo kinahitaji kuamilishwa kivyake):

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

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

Unaweza kuwezesha tabo binafsi kwa njia kadhaa:

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

Fifisha athari

Ili kufanya vichupo kufifia, ongeza .fadekwa kila .tab-pane. Kidirisha cha kichupo cha kwanza lazima pia kiwe na .showmaudhui ya awali kuonekana.

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

Mbinu

Njia za Asynchronous na mabadiliko

Njia zote za API ni za asynchronous na zinaanzisha mpito . Wanarudi kwa mpigaji mara tu mpito unapoanza lakini kabla haujaisha . Kwa kuongeza, simu ya mbinu kwenye sehemu ya mpito itapuuzwa .

Tazama hati zetu za JavaScript kwa maelezo zaidi .

Huwasha maudhui yako kama kipengele cha kichupo.

Unaweza kuunda mfano wa tabo na mjenzi, kwa mfano:

const bsTab = new bootstrap.Tab('#myTab')
Njia Maelezo
dispose Huharibu kichupo cha kipengele.
getInstance Njia tuli ambayo hukuruhusu kupata mfano wa tabo inayohusishwa na kipengee cha DOM, unaweza kuitumia kama hii: bootstrap.Tab.getInstance(element).
getOrCreateInstance Mbinu tuli ambayo inarejesha mfano wa kichupo kinachohusishwa na kipengele cha DOM au kuunda kipya iwapo hakijaanzishwa. Unaweza kuitumia kama hii bootstrap.Tab.getOrCreateInstance(element):.
show Huchagua kichupo kilichotolewa na kuonyesha kidirisha chake kinachohusiana. Kichupo kingine chochote ambacho kilichaguliwa hapo awali kitaacha kuchaguliwa na kidirisha chake kinachohusishwa hufichwa. Hurejesha kwa mpigaji kabla kidirisha cha kichupo hakijaonyeshwa (yaani kabla ya shown.bs.tabtukio kutokea).

Matukio

Wakati wa kuonyesha kichupo kipya, matukio huwaka kwa mpangilio ufuatao:

  1. hide.bs.tab(kwenye kichupo kinachotumika sasa)
  2. show.bs.tab(kwenye kichupo cha-kuonyeshwa)
  3. hidden.bs.tab(kwenye kichupo amilifu kilichotangulia, sawa na cha hide.bs.tabtukio)
  4. shown.bs.tab(kwenye kichupo kipya-kilichoonyeshwa, sawa na cha show.bs.tabtukio)

Ikiwa hakuna kichupo kilichokuwa tayari kinatumika, basi matukio hide.bs.tabna hidden.bs.tabmatukio hayatafutwa.

Aina ya tukio Maelezo
hide.bs.tab Tukio hili huwaka wakati kichupo kipya kitaonyeshwa (na kwa hivyo kichupo amilifu cha awali kitafichwa). Tumia event.targetna event.relatedTargetkulenga kichupo kinachotumika sasa na kichupo kipya kitakachotumika hivi karibuni, mtawalia.
hidden.bs.tab Tukio hili huwaka baada ya kichupo kipya kuonyeshwa (na kwa hivyo kichupo amilifu cha awali kimefichwa). Tumia event.targetna event.relatedTargetkulenga kichupo amilifu cha awali na kichupo kipya kinachotumika, mtawalia.
show.bs.tab Tukio hili linawaka kwenye onyesho la kichupo, lakini kabla ya kichupo kipya kuonyeshwa. Tumia event.targetna event.relatedTargetkulenga kichupo amilifu na kichupo amilifu cha awali (kama kinapatikana) mtawalia.
shown.bs.tab Tukio hili huwashwa kwenye onyesho la kichupo baada ya kichupo kuonyeshwa. Tumia event.targetna event.relatedTargetkulenga kichupo amilifu na kichupo amilifu cha awali (kama kinapatikana) mtawalia.
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
})