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.
<ul class="nav">
  <li class="nav-item">
    <a class="nav-link active" 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" 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" 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" 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" 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" 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" 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" 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" 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" 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" 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" 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" 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.

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" href="#">Active</a>
  </li>
  <li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <a class="dropdown-item" href="#">Something else here</a>
      <div class="dropdown-divider"></div>
      <a class="dropdown-item" href="#">Separated link</a>
    </div>
  </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" href="#">Active</a>
  </li>
  <li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <a class="dropdown-item" href="#">Something else here</a>
      <div class="dropdown-divider"></div>
      <a class="dropdown-item" href="#">Separated link</a>
    </div>
  </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>

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.

Idan kuna gina JavaScript ɗin mu daga tushe, yana buƙatarutil.js .

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, ayyukansu da yanayin 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 shafin JavaScript plugin ɗin baya 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.

Abubuwan da ke riƙe da wuri don rukunin shafin. Wannan yana da alaƙa da shafin gida. Yana ɗaukan ku mil, tsayi sosai, saboda tana da wannan murmushin ƙasa ɗaya. Akwai wani bako a gadona, wani irin bugun kai na ke yi. Oh, a'a. A wata rayuwa zan sa ku zauna. 'Saboda ni, Ina iya komai. Wanda ya dace da yaƙi na rawa. An saba sace giyar iyayenku da hawan rufin. Sautin, tan daidaita kuma a shirye, kunna shi yana haifar da nauyi. Soyayyarta kamar magani ce. Ina tsammanin na manta ina da zabi.

Abubuwan da ke riƙe da wuri don rukunin shafin. Wannan yana da alaƙa da shafin bayanin martaba. Kun sami mafi kyawun gine-gine. Tambarin fasfo, tana da duniya. Lafiya, sabo, mai zafi, mun same shi a kulle. Ban taba shirya cewa wata rana zan rasa ku ba. Ta cinye zuciyarka. Sumbatar ku tana da kyau, kowane motsi sihiri ne. Ina nufin wadanda, ina nufin kamar ita ce. Gaisuwa da masoya mu yi tafiya. Kawai mallaki dare kamar 4 ga Yuli! Amma ka gwammace a bata.

Placeholder content for the tab panel. This one relates to the contact tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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.

Abubuwan da ke riƙe da wuri don rukunin shafin. Wannan yana da alaƙa da shafin gida. Yana ɗaukan ku mil, tsayi sosai, saboda tana da wannan murmushin ƙasa ɗaya. Akwai wani bako a gadona, wani irin bugun kai na ke yi. Oh, a'a. A wata rayuwa zan sa ku zauna. 'Saboda ni, Ina iya komai. Wanda ya dace da yaƙi na rawa. An saba sace giyar iyayenku da hawan rufin. Sautin, tan daidaita kuma a shirye, kunna shi yana haifar da nauyi. Soyayyarta kamar magani ce. Ina tsammanin na manta ina da zabi.

Placeholder content for the tab panel. This one relates to the profile tab. You got the finest architecture. Passport stamps, she's cosmopolitan. Fine, fresh, fierce, we got it on lock. Never planned that one day I'd be losing you. She eats your heart out. Your kiss is cosmic, every move is magic. I mean the ones, I mean like she's the one. Greetings loved ones let's take a journey. Just own the night like the 4th of July! But you'd rather get wasted.

Placeholder content for the tab panel. This one relates to the contact tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.

<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-toggle="pill" data-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-toggle="pill" data-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-toggle="pill" data-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.

Abubuwan da ke riƙe da wuri don rukunin shafin. Wannan yana da alaƙa da shafin gida. Na gan ku cikin gari kuna waƙar Buluu. Kalli yadda kuke kewaya magudanar ruwa. Me yasa baki barni na tsaya ba? Nauyi ne kan da ke sa kambi. I, muna sa mala’iku kuka, suna ruwan sama a duniya daga sama. Ina son ganin nunin a cikin 3D, fim. Shin kun taɓa ji, ji kamar siriri takarda. Ee ko a'a ne, a'a watakila.

Placeholder content for the tab panel. This one relates to the profile tab. Takes you miles high, so high, 'cause she’s got that one international smile. There's a stranger in my bed, there's a pounding in my head. Oh, no. In another life I would make you stay. ‘Cause I, I’m capable of anything. Suiting up for my crowning battle. Used to steal your parents' liquor and climb to the roof. Tone, tan fit and ready, turn it up cause its gettin' heavy. Her love is like a drug. I guess that I forgot I had a choice.

Placeholder content for the tab panel. This one relates to the messages tab. You got the finest architecture. Passport stamps, she's cosmopolitan. Fine, fresh, fierce, we got it on lock. Never planned that one day I'd be losing you. She eats your heart out. Your kiss is cosmic, every move is magic. I mean the ones, I mean like she's the one. Greetings loved ones let's take a journey. Just own the night like the 4th of July! But you'd rather get wasted.

Placeholder content for the tab panel. This one relates to the settings tab. Her love is like a drug. All my girls vintage Chanel baby. Got a motel and built a fort out of sheets. 'Cause she's the muse and the artist. (This is how we do) So you wanna play with magic. So just be sure before you give it all to me. I'm walking, I'm walking on air (tonight). Skip the talk, heard it all, time to walk the walk. Catch her if you can. Stinging like a bee I earned my stripes.

<div class="row">
  <div class="col-3">
    <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
      <button class="nav-link active" id="v-pills-home-tab" data-toggle="pill" data-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-toggle="pill" data-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-toggle="pill" data-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-toggle="pill" data-target="#v-pills-settings" type="button" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</button>
    </div>
  </div>
  <div class="col-9">
    <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>
</div>

Amfani da bayanan halayen

Kuna iya kunna shafi ko kewayawa kwaya ba tare da rubuta kowane JavaScript ba ta hanyar tantancewa kawai data-toggle="tab"ko data-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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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):

$('#myTab button').on('click', function (event) {
  event.preventDefault()
  $(this).tab('show')
})

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

$('#myTab button[data-target="#profile"]').tab('show') // Select tab by name
$('#myTab li:first-child button').tab('show') // Select first tab
$('#myTab li:last-child button').tab('show') // Select last tab
$('#myTab li:nth-child(3) button').tab('show') // Select third 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 .

$().taba

Yana kunna abun shafi da kwandon abun ciki. Tab ya kamata ya sami ko dai a data-targetko, idan ana amfani da hanyar haɗin gwiwa, hrefsifa mai 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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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-toggle="tab" data-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>
  $(function () {
    $('#myTab li:last-child button').tab('show')
  })
</script>

.tab('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).

$('#someTab').tab('show')

.tab('zuba')

Yana lalata shafin wani abu.

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
nuna.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.
nuna.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.
boye.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.
boye.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.
$('button[data-toggle="tab"]').on('shown.bs.tab', function (event) {
  event.target // newly activated tab
  event.relatedTarget // previous active tab
})