Tsallake zuwa babban abun ciki Tsallake zuwa kewayawa na takardu
Check
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.

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>

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.

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>

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:

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>

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

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

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>

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

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>

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 .

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>

Kwayoyin cuta

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

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>

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.

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>

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

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>

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.

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>

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

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>

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.

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>

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 kawai don musaya masu ɗauri, kamar yadda aka bayyana a cikin tsarin Shafukan Jagorar Ayyukan Marubuta 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

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>

Kwayoyin cuta masu zazzagewa

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

Masu canji

An ƙara a cikin v5.2.0

A matsayin wani ɓangare na tsarin canza canjin CSS na Bootstrap, jiragen ruwa a yanzu suna amfani da masu canjin CSS na gida akan .nav, .nav-tabs, da kuma .nav-pillsinganta ingantaccen lokaci na gaske. An saita dabi'u don masu canjin CSS ta hanyar Sass, don haka har yanzu ana tallafawa keɓancewar Sass, ma.

A kan .navajin tushe:

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

A kan .nav-tabsaji mai gyara:

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

A kan .nav-pillsaji mai gyara:

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

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.

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.

Wannan shi ne wasu abun ciki mai ɗaukar hoto abun ciki mai alaƙa da bayanin martaba . 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 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>

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

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.

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>

Kuma da kwayoyi na tsaye. Da kyau, don shafuka na tsaye, yakamata ku ƙara aria-orientation="vertical"zuwa kwandon jerin shafuka.

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

Dama

Matsaloli masu ƙarfi masu ƙarfi, kamar yadda aka bayyana a cikin tsarin ARIA Jagorar Ayyukan Marubuci , suna buƙatar role="tablist", role="tab", role="tabpanel", da ƙarin aria-sifofi don isar da tsarinsu, aikinsu, 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.

A cikin layi tare da tsarin Ayyukan Rubuce-rubucen ARIA, shafin da ke aiki a halin yanzu kawai yana karɓar mayar da hankali kan madannai. Lokacin da aka ƙaddamar da plugin ɗin JavaScript, zai saita tabindex="-1"akan duk sarrafa shafin mara aiki. Da zarar shafin mai aiki a halin yanzu ya mayar da hankali, maɓallan siginan kwamfuta suna kunna shafin da ya gabata/na gaba, tare da plugin ɗin yana canza motsitabindex daidai. Duk da haka, lura cewa plugin ɗin JavaScript ba ya bambanta tsakanin jeri na kwance da na tsaye idan ya zo ga hulɗar maɓalli na maɓalli: ba tare da la'akari da daidaitawar jerin abubuwan ba, duka siginan kwamfuta na sama da hagu suna zuwa shafin da ya gabata, kuma ƙasa da siginan dama je zuwa. shafi na gaba.

Gabaɗaya, don sauƙaƙe kewayawa na madannai, ana ba da shawarar sanya bangarorin shafin su ma su mai da hankali sosai, sai dai in an riga an fi mayar da hankali kan kashi na farko mai ɗauke da ma'ana a cikin rukunin shafin. Fasinjojin JavaScript ba ya ƙoƙarin sarrafa wannan al'amari-inda ya dace, kuna buƙatar sanya fa'idodin shafin ku a bayyane ta ƙara tabindex="0"a cikin alamarku.
Shafukan JavaScript na shafin ba ya goyan bayan musaya masu alaƙa waɗanda ke ƙunshe da menu na zazzagewa, saboda waɗannan suna 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.

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

Ta hanyar JavaScript

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

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

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

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

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

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

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 .

Yana kunna abun cikin ku azaman ɓangaren shafi.

Kuna iya ƙirƙirar misalin shafi tare da mai gini, misali:

const bsTab = new bootstrap.Tab('#myTab')
Hanya Bayani
dispose Yana lalata shafin wani abu.
getInstance Hanyar a tsaye wacce ke ba ku damar samun misalin shafin da ke da alaƙa da nau'in DOM, zaku iya amfani da shi kamar haka: bootstrap.Tab.getInstance(element).
getOrCreateInstance Hanya madaidaiciya wacce ke dawo da misalin shafin da ke da alaƙa da abun DOM ko ƙirƙirar sabo idan ba a fara shi ba. Kuna iya amfani da shi kamar haka bootstrap.Tab.getOrCreateInstance(element):.
show 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).

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