Aqbeż għall-kontenut prinċipali Aqbeż għan-navigazzjoni tad-dokumenti
in English

Navs u tabs

Dokumentazzjoni u eżempji ta' kif tuża l-komponenti ta' navigazzjoni inklużi ta' Bootstrap.

Base nav

In-navigazzjoni disponibbli f'Bootstrap jaqsmu markup ġenerali u stili, mill- .navklassi bażi għall-istati attivi u b'diżabilità. Ibdel il-klassijiet tal-modifikatur biex taqleb bejn kull stil.

Il- .navkomponent bażi huwa mibni bil-flexbox u jipprovdi pedament b'saħħtu għall-bini ta 'kull tip ta' komponenti ta 'navigazzjoni. Jinkludi xi stil overrides (għal ħidma ma 'listi), xi link padding għal żoni akbar hit, u stil bażiku b'diżabilità.

Il- .navkomponent bażi ma jinkludi l-ebda .activestat. L-eżempji li ġejjin jinkludu l-klassi, prinċipalment biex juru li din il-klassi partikolari ma tagħtix bidu għal xi stil speċjali.

Biex twassal l-istat attiv għal teknoloġiji ta 'assistenza, uża l- aria-currentattribut — billi tuża l- pagevalur għall-paġna kurrenti, jew truegħall-oġġett kurrenti f'sett.

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

Il-klassijiet jintużaw tul, għalhekk il-markup tiegħek jista 'jkun super flessibbli. Uża <ul>s bħal hawn fuq, <ol>jekk l-ordni tal-oġġetti tiegħek hija importanti, jew irrombla tiegħek <nav>b'element. Minħabba li l- .navużi display: flex, il-links tan-nav iġibu ruħhom l-istess bħall-oġġetti tan-nav, iżda mingħajr il-markup żejjed.

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

Stili disponibbli

Ibdel l-istil tal .nav-komponent s b'modifikaturi u utilitajiet. Ħallat u qabbel kif meħtieġ, jew ibni tiegħek.

Allinjament orizzontali

Ibdel l-allinjament orizzontali tan-nav tiegħek b'utilitajiet tal- flexbox . B'mod awtomatiku, in-navs huma allinjati max-xellug, iżda tista 'faċilment tibdelhom lejn iċ-ċentru jew il-lemin.

Iċċentrat ma' .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>

Allinjat mal-lemin ma' .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>

Vertikali

Stack in-navigazzjoni tiegħek billi tbiddel id-direzzjoni tal-oġġett flex bl- .flex-columnutilità. Għandek bżonn tiġborhom fuq xi viewports iżda mhux oħrajn? Uża l-verżjonijiet li jirrispondu (eż, .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>

Bħal dejjem, in-navigazzjoni vertikali hija possibbli mingħajr <ul>s, ukoll.

<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

Jieħu n-nav bażiku minn fuq u żżid il- .nav-tabsklassi biex tiġġenera interface b'tabbed. Użahom biex toħloq reġjuni tabbable bil- plugin tagħna tat-tab 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>

Pilloli

Ħu dak l-istess HTML, imma uża .nav-pillsminflok:

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

Imla u ġġustifika

Ġigħel il- .navkontenut tiegħek biex jestendi l-wisa 'sħiħ disponibbli waħda minn żewġ klassijiet ta' modifikatur. Biex timla l-ispazju kollu disponibbli b'mod proporzjonali bl- .nav-itemi tiegħek, uża .nav-fill. Innota li l-ispazju orizzontali kollu huwa okkupat, iżda mhux kull oġġett tan-nav għandu l-istess wisa '.

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

Meta tuża <nav>navigazzjoni bbażata fuq, tista 'tħalli barra b'mod sikur .nav-itemkif huwa meħtieġ biss għall- elementi .nav-linktal-grafika .<a>

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

Għal elementi ta' wisa' ugwali, uża .nav-justified. L-ispazju orizzontali kollu se jkun okkupat minn links tan-nav, iżda b'differenza .nav-fillminn hawn fuq, kull oġġett tan-nav se jkun l-istess wisa '.

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

Simili għall- .nav-filleżempju bl-użu ta ' <nav>navigazzjoni bbażata fuq.

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

Ħidma ma 'utilitajiet flex

Jekk għandek bżonn varjazzjonijiet tan-nav li jirrispondu, ikkunsidra li tuża serje ta ' utilitajiet tal-flexbox . Filwaqt li huma aktar verbose, dawn l-utilitajiet joffru customization akbar madwar breakpoints li jirrispondu. Fl-eżempju hawn taħt, in-nav tagħna se jkun f'munzelli fuq l-iktar breakpoint baxx, imbagħad jadatta għal tqassim orizzontali li jimla l-wisa 'disponibbli li jibda mill-breakpoint żgħir.

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

Rigward l-aċċessibbiltà

Jekk qed tuża navs biex tipprovdi bar tan-navigazzjoni, kun żgur li żżid role="navigation"mal-kontenitur ġenitur l-aktar loġiku tal- <ul>, jew wrap <nav>element madwar in-navigazzjoni kollha. Iżżidx ir-rwol mal- <ul>persuna nfisha, peress li dan jipprevjeni milli jitħabbar bħala lista attwali minn teknoloġiji ta' assistenza.

Innota li l-vireg tan-navigazzjoni, anki jekk viżwalment stilati bħala tabs mal- .nav-tabsklassi, m'għandhomx jingħataw role="tablist", role="tab"jew role="tabpanel"attributi. Dawn huma xierqa biss għal interfaces b'tabbed dinamiċi, kif deskritt fil- Prattiċi tal-Awtorjar WAI ARIA . Ara l-imġiba JavaScript għal interfaces b'tabbed dinamiċi f'din it-taqsima għal eżempju. L- aria-currentattribut mhuwiex meħtieġ fuq interfaces b'tabbed dinamiċi peress li JavaScript tagħna jimmaniġġja l-istat magħżul billi jżid aria-selected="true"fuq it-tab attiva.

Bl-użu dropdowns

Żid menus dropdown bi ftit HTML żejjed u l- plugin JavaScript dropdowns .

Tabs bi dropdowns

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

Pilloli bi dropdowns

<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

Varjabbli

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

Imġieba JavaScript

Uża t-tab JavaScript plugin—inkludih individwalment jew permezz tal- bootstrap.jsfajl ikkumpilat—biex testendi t-tabs u l-pilloli tan-navigazzjoni tagħna biex toħloq panewijiet tabbable ta' kontenut lokali.

Interfaces b'tabbed dinamiċi, kif deskritti fil- Prattiċi ta' Awtur WAI ARIA , jeħtieġu role="tablist", role="tab", role="tabpanel", u aria-attributi addizzjonali sabiex iwasslu l-istruttura, il-funzjonalità u l-istat attwali tagħhom lill-utenti ta 'teknoloġiji ta' assistenza (bħal screen readers). Bħala l-aħjar prattika, nirrakkomandaw li tuża <button>elementi għat-tabs, peress li dawn huma kontrolli li jikkawżaw bidla dinamika, aktar milli links li jinnavigaw għal paġna jew post ġdid.

Innota li l-interfaces b'tabbed dinamiċi m'għandux ikun fihom menus dropdown, peress li dan jikkawża kwistjonijiet kemm ta 'użabilità kif ukoll ta' aċċessibbiltà. Mill-perspettiva tal-użabilità, il-fatt li l-element grillu tat-tab murija bħalissa mhux viżibbli immedjatament (għaliex huwa ġewwa l-menu dropdown magħluq) jista 'jikkawża konfużjoni. Mil-lat ta' aċċessibbiltà, bħalissa m'hemm l-ebda mod sensibbli biex din it-tip ta' kostruzzjoni tiġi mmappjata għal mudell WAI ARIA standard, li jfisser li ma jistax jinftiehem faċilment mill-utenti ta 'teknoloġiji ta' assistenza.

Dan huwa xi kontenut ta' placeholder il-kontenut assoċjat tat-tab Home. Meta tikklikkja tab oħra se taqleb il-viżibilità ta' din għal dik li jmiss. It-tab JavaScript tbiddel il-klassijiet biex tikkontrolla l-viżibilità tal-kontenut u l-istil. Tista 'tużah ma' tabs, pilloli, u kwalunkwe .navnavigazzjoni oħra li taħdem.

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>

Biex tgħin jaqbel mal-bżonnijiet tiegħek, dan jaħdem <ul>b'markup ibbażat fuq -, kif muri hawn fuq, jew bi kwalunkwe markup arbitrarju "roll your own". Innota li jekk qed tuża <nav>, m'għandekx iżżid role="tablist"direttament miegħu, peress li dan jegħleb ir-rwol nattiv tal-element bħala punt ta' referenza tan-navigazzjoni. Minflok, aqleb għal element alternattiv (fl-eżempju hawn taħt, sempliċi <div>) u wrap <nav>madwaru.

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

Il-plugin tat-tabs jaħdem ukoll bil-pilloli.

Dan huwa xi kontenut ta' placeholder il-kontenut assoċjat tat-tab Home. Meta tikklikkja tab oħra se taqleb il-viżibilità ta' din għal dik li jmiss. It-tab JavaScript tbiddel il-klassijiet biex tikkontrolla l-viżibilità tal-kontenut u l-istil. Tista 'tużah ma' tabs, pilloli, u kwalunkwe .navnavigazzjoni oħra li taħdem.

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>

U b'pilloli vertikali.

Dan huwa xi kontenut ta' placeholder il-kontenut assoċjat tat-tab Home. Meta tikklikkja tab oħra se taqleb il-viżibilità ta' din għal dik li jmiss. It-tab JavaScript tbiddel il-klassijiet biex tikkontrolla l-viżibilità tal-kontenut u l-istil. Tista 'tużah ma' tabs, pilloli, u kwalunkwe .navnavigazzjoni oħra li taħdem.

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>

L-użu ta' attributi tad-data

Tista' tattiva tab jew navigazzjoni ta' pillola mingħajr ma tikteb JavaScript billi sempliċement tispeċifika data-bs-toggle="tab"jew data-bs-toggle="pill"fuq element. Uża dawn l-attributi tad-dejta fuq .nav-tabsjew .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>

Via JavaScript

Ippermetti tabs tabbable permezz ta' JavaScript (kull tab trid tiġi attivata individwalment):

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

Tista' tattiva tabs individwali b'diversi modi:

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

Effett fade

Biex tagħmel it-tabs fade, żid .fadema 'kull .tab-pane. L-ewwel pannell tat-tab irid ikollu wkoll .showjagħmel il-kontenut inizjali viżibbli.

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

Metodi

Metodi asinkroniċi u tranżizzjonijiet

Il-metodi kollha tal-API huma asinkroniċi u jibdew transizzjoni . Jirritornaw għand min iċempel hekk kif tinbeda t-tranżizzjoni iżda qabel ma tispiċċa . Barra minn hekk, sejħa ta' metodu fuq komponent ta' tranżizzjoni se tiġi injorata .

Ara d-dokumentazzjoni JavaScript tagħna għal aktar informazzjoni .

constructor

Jattiva element tab u kontenitur tal-kontenut. Tab għandu jkollha data-bs-targetjew, jekk tuża rabta, hrefattribut, li jimmira lejn nodu tal-kontenitur fid-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>

juru

Jagħżel it-tab mogħtija u juri l-ħġieġa assoċjata tagħha. Kwalunkwe tab oħra li kienet magħżula qabel issir mhux magħżula u l-ħġieġa assoċjata tagħha hija moħbija. Jirritorna lil min iċempel qabel ma l-panew tat-tab fil-fatt intwera (jiġifieri qabel ma shown.bs.tabjseħħ l-avveniment).

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

  tab.show()

jiddisponi

Jeqred tab ta' element.

getInstance

Metodu statiku li jippermettilek li tikseb l-istanza tat-tab assoċjata ma 'element DOM

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

getOrCreateInstance

Metodu statiku li jippermettilek li tikseb l-istanza tat-tab assoċjata ma 'element DOM, jew toħloq waħda ġdida f'każ li ma kinitx inizjalizzata

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

Avvenimenti

Meta turi tab ġdida, l-avvenimenti jisparaw fl-ordni li ġejja:

  1. hide.bs.tab(fuq it-tab attiva attwali)
  2. show.bs.tab(fuq it-tab li trid tintwera)
  3. hidden.bs.tab(fuq it-tab attiva preċedenti, l-istess bħal għall- hide.bs.tabavveniment)
  4. shown.bs.tab(fuq it-tab li għadha kif intwera, l-istess bħal dik tal- show.bs.tabavveniment)

Jekk l-ebda tab ma kienet diġà attiva, allura l- hide.bs.tabu hidden.bs.tabavvenimenti mhux se jiġu sparati.

Tip ta' avveniment Deskrizzjoni
show.bs.tab Dan l-avveniment jispara fuq tab show, iżda qabel ma tkun intweriet it-tab il-ġdida. Uża event.targetu event.relatedTargetbiex timmira t-tab attiva u t-tab attiva preċedenti (jekk disponibbli) rispettivament.
shown.bs.tab Dan l-avveniment jispara fuq tab show wara li tkun intweriet tab. Uża event.targetu event.relatedTargetbiex timmira t-tab attiva u t-tab attiva preċedenti (jekk disponibbli) rispettivament.
hide.bs.tab Dan l-avveniment jispara meta trid tintwera tab ġdida (u għalhekk it-tab attiva preċedenti trid tinħeba). Uża event.targetu event.relatedTargetbiex timmira t-tab attiva attwali u t-tab il-ġdida li dalwaqt tkun attiva, rispettivament.
hidden.bs.tab Dan l-avveniment jispara wara li tintwera tab ġdida (u għalhekk it-tab attiva preċedenti hija moħbija). Uża event.targetu event.relatedTargetbiex timmira t-tab attiva preċedenti u t-tab attiva l-ġdida, rispettivament.
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
})