Aqbeż għall-kontenut prinċipali Aqbeż għan-navigazzjoni tad-dokumenti
Check
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.

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>

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.

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>

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:

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>

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

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

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>

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

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

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 .

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>

Pilloli

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

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>

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

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>

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>

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>

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

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>

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

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>

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

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>

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- mudell ta' tabs tal-Gwida tal-Prattiċi tal-Awtur tal-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

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>

Pilloli bi dropdowns

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

Varjabbli

Miżjud fi v5.2.0

Bħala parti mill-approċċ tal-varjabbli CSS li qed jevolvu ta' Bootstrap, in-navs issa jużaw varjabbli CSS lokali fuq .nav, .nav-tabs, u .nav-pillsgħal customization mtejba f'ħin reali. Il-valuri għall-varjabbli CSS huma stabbiliti permezz ta 'Sass, għalhekk il-personalizzazzjoni ta' Sass għadha appoġġjata wkoll.

Fuq il .nav-klassi bażi:

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

Fuq il- .nav-tabsklassi modifikatur:

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

Fuq il- .nav-pillsklassi modifikatur:

  --#{$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 varjabbli

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

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.

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.

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>

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

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.

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>

U b'pilloli vertikali. Idealment, għal tabs vertikali, għandek iżżid ukoll aria-orientation="vertical"mal-kontenitur tal-lista tat-tab.

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

Aċċessibilità

Interfaces b'tabbed dinamiċi, kif deskritt fil- mudell ta' tabs tal-Gwida tal-Prattiċi tal-Awtur tal-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.

F'konformità mal-mudell tal-Prattiċi tal-Awtur tal-ARIA, it-tab attiva bħalissa biss tirċievi fokus fuq it-tastiera. Meta l-plugin JavaScript jiġi inizjalizzat, se jissettja tabindex="-1"fuq il-kontrolli kollha tat-tab inattivi. Ladarba t-tab attiva bħalissa għandha fokus, iċ-ċwievet tal-cursor jattivaw it-tab ta 'qabel/li jmiss, bil-plugin ibiddel il- rovingtabindex kif xieraq. Madankollu, innota li l-plugin JavaScript ma jiddistingwix bejn listi ta 'tab orizzontali u vertikali meta niġu għall-interazzjonijiet taċ-ċavetta tal-cursor: irrispettivament mill-orjentazzjoni tal-lista tat-tab, kemm il- cursor 'il fuq kif ukoll ix- xellug imorru għat-tab ta' qabel, u l-cursor 'l isfel u l- lemin imorru għal it-tab li jmiss.

B'mod ġenerali, biex tiġi ffaċilitata n-navigazzjoni bit-tastiera, huwa rrakkomandat li l-pannelli tat-tab infushom ikunu ffukabbli wkoll, sakemm l-ewwel element li fih kontenut sinifikanti ġewwa l-pannell tat-tab ma jkunx diġà ffukabbli. Il-plugin JavaScript ma jipprovax jimmaniġġa dan l-aspett—fejn xieraq, ikollok bżonn tagħmel il-pannelli tat-tab tiegħek b'mod espliċitu ffukabbli billi żżid tabindex="0"il-markup tiegħek.
Il-plugin JavaScript tat-tab ma jappoġġjax interfaces b'tabbed li fihom menus dropdown, peress li dawn jikkawżaw 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.

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

Via JavaScript

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

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

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

Tista' tattiva tabs individwali b'diversi modi:

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

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

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 .

Jattiva l-kontenut tiegħek bħala element tab.

Tista 'toħloq eżempju ta' tab mal-kostruttur, pereżempju:

const bsTab = new bootstrap.Tab('#myTab')
Metodu Deskrizzjoni
dispose Jeqred tab ta' element.
getInstance Metodu statiku li jippermettilek li tikseb l-istanza tat-tab assoċjata ma 'element DOM, tista' tużah bħal dan: bootstrap.Tab.getInstance(element).
getOrCreateInstance Metodu statiku li jirritorna istanza ta 'tab assoċjata ma' element DOM jew toħloq waħda ġdida f'każ li ma kinitx inizjalizzata. Tista' tużah bħal dan: bootstrap.Tab.getOrCreateInstance(element).
show 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).

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