Ruka hadi kwa yaliyomo kuu Ruka hadi kwenye urambazaji wa hati
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.

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

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

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

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

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

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

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

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

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

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

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

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

<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 Mazoea ya Uandishi ya WAI 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 amilifu.

Kwa kutumia menyu kunjuzi

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

Vichupo vilivyo na menyu kunjuzi

<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

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

Sass

Vigezo

$nav-link-padding-y:                .5rem;
$nav-link-padding-x:                1rem;
$nav-link-font-size:                null;
$nav-link-font-weight:              null;
$nav-link-color:                    $link-color;
$nav-link-hover-color:              $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.

Violesura vyenye vichupo vinavyobadilika, kama ilivyofafanuliwa katika Mbinu za Uandishi za WAI ARIA , zinahitaji 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.

Kumbuka kuwa violesura vya vichupo vinavyobadilika havipaswi kuwa na menyu kunjuzi, kwa kuwa hii 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 kuweka muundo wa aina hii kwa muundo wa kawaida wa WAI ARIA, kumaanisha kuwa hauwezi kueleweka kwa urahisi kwa watumiaji wa teknolojia saidizi.

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.

<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="contact-tab" data-bs-toggle="tab" data-bs-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Contact</button>
  </li>
</ul>
<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
  <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</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>
  </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">...</div>
  <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">...</div>
  <div class="tab-pane fade" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab">...</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.

<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>
</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">...</div>
  <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">...</div>
  <div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">...</div>
</div>

Na kwa vidonge vya wima.

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 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-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">...</div>
    <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">...</div>
    <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">...</div>
    <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">...</div>
  </div>
</div>

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">...</div>
  <div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
  <div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
  <div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
</div>

Kupitia JavaScript

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

var triggerTabList = [].slice.call(document.querySelectorAll('#myTab button'))
triggerTabList.forEach(function (triggerEl) {
  var tabTrigger = new bootstrap.Tab(triggerEl)

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

Unaweza kuwezesha tabo binafsi kwa njia kadhaa:

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

var 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">...</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
  <div class="tab-pane fade" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
  <div class="tab-pane fade" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</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 .

constructor

Huwasha kipengele cha kichupo na kontena ya maudhui. Kichupo kinapaswa kuwa na data-bs-targetau, ikiwa kinatumia kiungo, hrefsifa, inayolenga nodi ya kontena katika DOM.

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

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

<script>
  var firstTabEl = document.querySelector('#myTab li:last-child button')
  var firstTab = new bootstrap.Tab(firstTabEl)

  firstTab.show()
</script>

onyesha

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

  var someTabTriggerEl = document.querySelector('#someTabTrigger')
  var tab = new bootstrap.Tab(someTabTriggerEl)

  tab.show()

tupa

Huharibu kichupo cha kipengele.

getInstance

Njia tuli ambayo hukuruhusu kupata mfano wa kichupo unaohusishwa na kipengee cha DOM

var triggerEl = document.querySelector('#trigger')
var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance

getOrCreateInstance

Njia tuli ambayo hukuruhusu kupata mfano wa kichupo unaohusishwa na kipengee cha DOM, au kuunda mpya ikiwa haikuanzishwa.

var triggerEl = document.querySelector('#trigger')
var tab = bootstrap.Tab.getOrCreateInstance(triggerEl) // Returns a Bootstrap tab instance

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
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.
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.
var tabEl = document.querySelector('button[data-bs-toggle="tab"]')
tabEl.addEventListener('shown.bs.tab', function (event) {
  event.target // newly activated tab
  event.relatedTarget // previous active tab
})