Tsallake zuwa babban abun ciki Tsallake zuwa kewayawa na takardu
in English

Navs da shafuka

Takaddun bayanai da misalai na yadda ake amfani da abubuwan haɗin kewayawa na Bootstrap.

Base nav

Ana samun kewayawa a cikin Bootstrap rabo na gaba ɗaya da salo, daga .navajin tushe zuwa jihohi masu aiki da nakasassu. Musanya azuzuwan masu gyara don canzawa tsakanin kowane salo.

An .navgina sashin tushe tare da flexbox kuma yana ba da tushe mai ƙarfi don gina kowane nau'ikan abubuwan kewayawa. Ya haɗa da wasu juyewar salo (don aiki tare da jeri), wasu fakitin hanyar haɗin gwiwa don manyan wuraren da aka buga, da salo na nakasassu na asali.

Bangaren tushe .navbai haɗa da kowace .activejiha ba. Misalai masu zuwa sun haɗa da ajin, musamman don nuna cewa wannan ajin ba ya haifar da wani salo na musamman.

Don isar da yanayi mai aiki zuwa fasahar taimako, yi amfani da aria-currentsifa - yin amfani da pageƙimar shafi na yanzu, ko truedon abu na yanzu a cikin saiti.

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

Ana amfani da azuzuwan gaba ɗaya, don haka alamar ku na iya zama mai sassauƙa sosai. Yi amfani <ul>da s kamar na sama, <ol>idan tsarin abubuwanku na da mahimmanci, ko mirgine naku tare da wani <nav>abu. Saboda .navamfanin display: flex, hanyoyin haɗin nav suna yin daidai da abubuwan nav, amma ba tare da ƙarin alamar ba.

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

Samfuran salo

Canja salon .navbangaren s tare da masu gyara da abubuwan amfani. Mix da daidaita yadda ake buƙata, ko gina naku.

Daidaito a kwance

Canja jeri a kwance na nav ɗinku tare da kayan aikin flexbox . Ta hanyar tsoho, navs suna daidaitawa zuwa hagu, amma zaka iya canza su cikin sauƙi zuwa tsakiya ko masu layi na dama.

A tsakiya tare da .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>

Daidaitacce tare da .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>

A tsaye

Tari kewayawar ku ta hanyar canza jagorar abu mai sassauƙa tare da .flex-columnmai amfani. Kuna buƙatar tara su akan wasu wuraren kallo amma ba wasu ba? Yi amfani da nau'ikan amsawa (misali, .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>

Kamar koyaushe, kewayawa tsaye yana yiwuwa ba tare <ul>da s ba, kuma.

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

Tabs

Yana ɗaukar maɓallin kewayawa na asali daga sama kuma yana ƙara .nav-tabsajin don samar da abin dubawa na tabbed. Yi amfani da su don ƙirƙirar yankuna masu iya aiki tare da shafin mu JavaScript plugin .

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

Kwayoyin cuta

Ɗauki HTML iri ɗaya, amma amfani .nav-pillsmaimakon:

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

Cika da gaskata

Tilasta .navabubuwan da ke cikin ku don tsawaita cikakken faɗin samuwa ɗaya daga cikin azuzuwan masu gyara guda biyu. Don cika duk sararin samaniya daidai da .nav-items ɗin ku, yi amfani da .nav-fill. Lura cewa duk sararin samaniya an mamaye shi, amma ba kowane abu na jirgin ruwa ne yake da faɗi ɗaya ba.

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

Lokacin amfani da <nav>tushen kewayawa, zaku iya tsallakewa cikin aminci .nav-itemkamar yadda kawai .nav-linkake buƙata don <a>abubuwa masu salo.

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

Don abubuwa masu faɗi daidai, yi amfani da .nav-justified. Duk sararin samaniyar da ke kwance za a shagaltar da su ta hanyar haɗin yanar gizo, amma ba kamar na .nav-fillsama ba, kowane abu na nav zai zama faɗi ɗaya.

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

Mai kama da .nav-fillmisalin ta amfani da <nav>maɓallin kewayawa.

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

Aiki tare da flex utilities

Idan kuna buƙatar bambance-bambancen kewayawa mai amsawa, yi la'akari da yin amfani da jerin kayan aikin flexbox . Yayin da karin magana, waɗannan abubuwan amfani suna ba da gyare-gyare mafi girma a duk wuraren faɗuwa. A cikin misalin da ke ƙasa, za a jera nav ɗin mu akan mafi ƙanƙanta wurin hutu, sa'an nan kuma ya dace da shimfidar shimfidar wuri wanda ke cike faɗuwar da ke akwai wanda ya fara daga ƙaramin wurin hutu.

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

Game da samun dama

Idan kana amfani da navs don samar da sandar kewayawa, tabbatar da ƙara role="navigation"zuwa mafi madaidaicin kwantena na iyaye na <ul>, ko kunsa wani <nav>abu a kewayen gabaɗayan kewayawa. Kada a ƙara rawar ga <ul>kanta, saboda wannan zai hana a sanar da shi a matsayin ainihin jeri ta hanyar fasahar taimako.

Lura cewa sandunan kewayawa, ko da an tsara su ta gani azaman shafuka tare da .nav-tabsajin, bai kamata a ba role="tablist", role="tab"ko role="tabpanel"sifofi ba. Waɗannan sun dace ne kawai don musaya masu tsauri, kamar yadda aka bayyana a cikin Ayyukan Marubuci na WAI ARIA . Dubi halayen JavaScript don mu'amala mai ƙarfi a cikin wannan sashe don misali. Siffar aria-currentba lallai ba ne akan musaya masu tsauri tun da JavaScript ɗin mu yana sarrafa yanayin da aka zaɓa ta ƙara aria-selected="true"akan shafin mai aiki.

Amfani da dropdowns

Ƙara menu na zaɓuka tare da ɗan ƙarin HTML da abubuwan da aka sauke JavaScript plugin .

Shafukan da zazzagewa

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

Kwayoyin cuta masu zazzagewa

<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

Masu canji

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

Halin JavaScript

Yi amfani da shafin JavaScript plugin-haɗa shi ɗaiɗaiku ko ta hanyar bootstrap.jsfayil ɗin da aka haɗe-don tsawaita shafukan kewayawa da kwaya don ƙirƙirar fakitin abubuwan cikin gida.

Ƙwararrun hanyoyin haɗin yanar gizo, kamar yadda aka bayyana a cikin Ayyukan Marubuta na WAI ARIA , suna buƙatar role="tablist", role="tab", role="tabpanel", da ƙarin aria-sifofi don isar da tsarin su, ayyukansu da halin yanzu ga masu amfani da fasahar taimako (kamar masu karanta allo). A matsayin mafi kyawun aiki, muna ba da shawarar amfani <button>da abubuwa don shafuka, saboda waɗannan abubuwan sarrafawa ne waɗanda ke haifar da canji mai ƙarfi, maimakon hanyoyin haɗin da ke kewaya zuwa sabon shafi ko wuri.

Lura cewa musaya mai ƙarfi bai kamata ya ƙunshi menus na zazzagewa ba, saboda wannan yana haifar da abubuwan amfani da dama. Daga hangen nesa mai amfani, gaskiyar cewa abin da ake nunawa shafin a halin yanzu ba a iya gani nan da nan (kamar yadda yake cikin rufaffiyar menu) na iya haifar da rudani. Daga mahangar samun dama, a halin yanzu babu wata hanya mai ma'ana don taswirar irin wannan ginin zuwa daidaitaccen tsarin WAI ARIA, ma'ana cewa ba za a iya fahimtar da shi cikin sauƙi ga masu amfani da fasahar taimako ba.

Wannan shi ne wasu abun ciki mai ɗaukar hoto abun ciki mai alaƙa da gidan shafin. Danna wani shafin zai juya ganuwa na wannan don na gaba. Shafin JavaScript yana musanya azuzuwan don sarrafa ganin abun ciki da salo. Kuna iya amfani da shi tare da shafuka, kwayoyi, da kowane .navkewayawa mai ƙarfi.

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>

Don taimakawa dacewa da buƙatun ku, wannan yana aiki tare da <ul>tushen alamar alama, kamar yadda aka nuna a sama, ko tare da kowane alamar “mirgina naku” na sabani. Lura cewa idan kana amfani da <nav>, bai kamata ka ƙara role="tablist"kai tsaye zuwa gare shi ba, saboda wannan zai ƙetare aikin ɗan ƙasa a matsayin alamar kewayawa. Madadin haka, canza zuwa wani zaɓi (a cikin misalin da ke ƙasa, mai sauƙi <div>) kuma kunsa <nav>kewaye da shi.

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

Abubuwan plugin ɗin shafuka kuma suna aiki tare da kwayoyi.

Wannan shi ne wasu abun ciki mai ɗaukar hoto abun ciki mai alaƙa da gidan shafin. Danna wani shafin zai juya ganuwa na wannan don na gaba. Shafin JavaScript yana musanya azuzuwan don sarrafa ganin abun ciki da salo. Kuna iya amfani da shi tare da shafuka, kwayoyi, da kowane .navkewayawa mai ƙarfi.

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>

Kuma da kwayoyi na tsaye.

Wannan shi ne wasu abun ciki mai ɗaukar hoto abun ciki mai alaƙa da gidan shafin. Danna wani shafin zai juya ganuwa na wannan don na gaba. Shafin JavaScript yana musanya azuzuwan don sarrafa ganin abun ciki da salo. Kuna iya amfani da shi tare da shafuka, kwayoyi, da kowane .navkewayawa mai ƙarfi.

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>

Amfani da bayanan halayen

Kuna iya kunna shafi ko kewayawa kwaya ba tare da rubuta kowane JavaScript ba ta hanyar tantancewa kawai data-bs-toggle="tab"ko data-bs-toggle="pill"akan wani abu. Yi amfani da waɗannan sifofin bayanan akan .nav-tabsko .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>

Ta hanyar JavaScript

Kunna shafukan da za a iya amfani da su ta hanyar JavaScript (kowane shafin yana buƙatar kunna shi daban):

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()
  })
})

Kuna iya kunna shafuka guda ɗaya ta hanyoyi da yawa:

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

Fade sakamako

Don sanya shafuka su shuɗe, ƙara .fadezuwa kowane .tab-pane. Rukunin shafin farko kuma dole ne ya .showsanya abun cikin farko a bayyane.

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

Hanyoyin

Hanyoyi masu daidaitawa da canji

Duk hanyoyin API ba daidai ba ne kuma suna fara canji . Suna komawa ga mai kiran da zarar an fara canji amma kafin ya ƙare . Bugu da ƙari, za a yi watsi da kiran hanya akan ɓangaren canji .

Duba takaddun JavaScript ɗin mu don ƙarin bayani .

constructor

Yana kunna abun shafi da kwandon abun ciki. Tab ya kamata ya sami ko dai a data-bs-targetko, idan ana amfani da hanyar haɗi, hrefsifa, wanda ke niyya da kumburin akwati a cikin 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>

nuna

Yana zaɓar shafin da aka bayar kuma yana nuna aikin haɗin gwiwa. Duk wani shafin da aka zaɓa a baya ya zama ba a zaɓa ba kuma ana ɓoye abin da ke tattare da shi. Komawa ga mai kira kafin a nuna ainihin ɓangaren shafin (watau kafin shown.bs.tababin ya faru).

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

  tab.show()

jefar

Yana lalata shafin wani abu.

samunInstance

Hanyar a tsaye wacce ke ba ka damar samun misalin shafin da ke da alaƙa da abin DOM

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

samunOrCreateInstance

Hanyar a tsaye wacce ke ba ku damar samun misalin shafin da ke da alaƙa da abin DOM, ko ƙirƙirar sabo idan ba a fara shi ba.

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

Abubuwan da suka faru

Lokacin nuna sabon shafin, abubuwan da suka faru sun yi wuta a cikin tsari mai zuwa:

  1. hide.bs.tab(a kan shafin mai aiki na yanzu)
  2. show.bs.tab(a kan shafin da za a nuna)
  3. hidden.bs.tab(akan shafin da ya gabata mai aiki, iri ɗaya da na hide.bs.tabtaron)
  4. shown.bs.tab(akan sabon shafin da aka nuna, iri ɗaya da na show.bs.tabtaron)

Idan babu shafin da ya riga ya fara aiki, to ba za a kori abubuwan hide.bs.tabda abubuwan da suka faru ba.hidden.bs.tab

Nau'in taron Bayani
show.bs.tab Wannan taron yana gobara akan nunin shafin, amma kafin a nuna sabon shafin. Yi amfani event.targetda event.relatedTargetniyya shafi mai aiki da shafin da ya gabata (idan akwai) bi da bi.
shown.bs.tab Wannan taron yana gobara akan nunin shafin bayan an nuna shafin. Yi amfani event.targetda event.relatedTargetniyya shafi mai aiki da shafin da ya gabata (idan akwai) bi da bi.
hide.bs.tab Wannan taron yana kunna wuta lokacin da za a nuna sabon shafin (don haka za a ɓoye shafin da ya gabata). Yi amfani event.targetda event.relatedTargetniyya shafi mai aiki na yanzu da sabon shafin da za a yi aiki nan ba da jimawa ba, bi da bi.
hidden.bs.tab Wannan taron yana gobara bayan an nuna sabon shafin (saboda haka shafin da ya gabata yana ɓoye). Yi amfani event.targetda event.relatedTargetniyya shafi na baya mai aiki da sabon shafin mai aiki, bi da bi.
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
})