Twe kɔ emu nsɛm atitiriw no so Twe kɔ docs navigation so
Check
in English

Navs ne tabs ahorow

Nwoma ne nhwɛsoɔ a ɛfa sɛdeɛ wɔde Bootstrap no akwantuo afã a ɛka ho no bedi dwuma.

Base nav

Navigation a ɛwɔ Bootstrap mu no kyɛ general markup ne styles, efi base .navclass no so kosi active ne disabled states so. Sesa modifier classes na dannan style biara ntam.

Wɔde flexbox na ɛkyekyee base .navcomponent no na ɛma fapem a ɛyɛ den a wɔde besi navigation components ahorow nyinaa. Ɛka style overrides binom (a wɔde yɛ adwuma wɔ lists ho), link padding bi ma hit areas akɛse, ne basic disabled styling.

Base .navcomponent no nka .activetebea biara ho. Nhwɛso ahorow a edidi so yi de adesuakuw no ka ho, titiriw de kyerɛ sɛ adesuakuw pɔtee yi nkanyan ɔkwan titiriw biara a wɔfa so yɛ no.

Sɛ wopɛ sɛ wode tebea a ɛyɛ adwuma no kɔ mfiridwuma a ɛboa mu a, fa aria-currentsu no di dwuma — fa pagebotae no di dwuma ma krataafa a ɛwɔ hɔ mprempren, anaasɛ trueade a ɛwɔ hɔ mprempren wɔ nhyehyɛe bi mu.

html na ɛwɔ hɔ
<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>

Wɔde adesua ahorow di dwuma wɔ ne nyinaa mu, enti wo markup betumi ayɛ super flexible. Fa <ul>s te sɛ atifi hɔ no di dwuma, sɛ wo nneɛma no nhyehyɛe ho hia a, anaasɛ fa element <ol>bi bobɔ w’ankasa de . <nav>Efisɛ .navuses display: flex, nav links no yɛ wɔn ade sɛnea nav nneɛma bɛyɛ no, nanso enni markup foforo no.

html na ɛwɔ hɔ
<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>

Nneɛma a wɔde yɛ nneɛma a ɛwɔ hɔ

Sesa .navs component no kwan so de modifiers ne utilities. Fa fra mu sɛnea ɛho hia, anaasɛ si w’ankasa de.

Horizontal a wɔde hyɛ mu

Sesa wo nav no horizontal alignment no ne flexbox utilities . Sɛnea wɔahyɛ no, navs no yɛ benkum so, nanso ɛnyɛ den sɛ wobɛsesa no akɔ mfinimfini anaa nifa so.

Mfinimfini ne .justify-content-center: .

html na ɛwɔ hɔ
<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>

Nifa-a ɛne .justify-content-end: .

html na ɛwɔ hɔ
<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>

Tenten mu

Stack wo navigation denam nsakrae a wobɛsesa flex ade no kwankyerɛ ne .flex-columnutility no so. Ɛho hia sɛ wo stack wɔn wɔ viewports binom so nanso ɛnyɛ afoforo so? Fa nkyerɛase ahorow a ɛyɛ mmuae no di dwuma (sɛ nhwɛso no, .flex-sm-column).

html na ɛwɔ hɔ
<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>

Sɛnea ɛte daa no, vertical navigation betumi ayɛ yiye a <ul>s nka ho, nso.

html na ɛwɔ hɔ
<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 ahorow

Fa nav titiriw no fi soro na ɛde .nav-tabsadesuakuw no ka ho ma ɛyɛ tabbed interface. Fa wɔn yɛ tabbable regions denam yɛn tab JavaScript plugin no so .

html na ɛwɔ hɔ
<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>

Nnuru a wɔde di dwuma

Fa saa HTML koro no ara, nanso fa di dwuma .nav-pillsmmom:

html na ɛwɔ hɔ
<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>

Hyɛ no ma na bu bem

Hyɛ wo .nav's mu nsɛm no ma ɛntrɛw ntrɛwmu a ɛwɔ hɔ nyinaa mu biako a ɛwɔ modifier class abien no mu. Sɛ wopɛ sɛ wode wo .nav-items hyɛ baabi a ɛwɔ hɔ nyinaa ma sɛnea ɛfata a, fa .nav-fill. Hyɛ no nsow sɛ wɔafa horizontal space nyinaa, nanso ɛnyɛ nav ade biara na ne tɛtrɛtɛ yɛ pɛ.

html na ɛwɔ hɔ
<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>

Sɛ wode <nav>-gyina navigation redi dwuma a, wubetumi ayi afi mu dwoodwoo .nav-itemsɛnea .nav-linkɛho hia ma styling <a>elements nkutoo.

html na ɛwɔ hɔ
<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>

Sɛ wopɛ nneɛma a ne tɛtrɛtɛ yɛ pɛ a, fa .nav-justified. Nav links bɛfa horizontal space nyinaa, nanso ɛnte sɛ .nav-fillatifi hɔ no, nav adeɛ biara bɛyɛ ne tɛtrɛtɛ korɔ.

html na ɛwɔ hɔ
<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>

Te sɛ .nav-fillnhwɛso a wɔde <nav>-gyina akwantuo so di dwuma no.

html na ɛwɔ hɔ
<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>

Adwuma a wɔde flex utilities yɛ

Sɛ wuhia nav nsakrae a ɛyɛ mmuae a, susuw ho sɛ wode flexbox utilities ahorow a ɛtoatoa so bedi dwuma . Bere a ɛyɛ verbose kɛse no, saa utilities yi ma customization kɛse wɔ mmuae breakpoints nyinaa mu. Wɔ nhwɛsoɔ a ɛwɔ aseɛ ha yi mu no, yɛn nav no bɛboaboa ano wɔ breakpoint a ɛba fam koraa no so, afei wɔbɛdane akɔ horizontal layout a ɛhyɛ width a ɛwɔ hɔ no ma a ɛfiri aseɛ firi breakpoint ketewa no so.

html na ɛwɔ hɔ
<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>

Ɛdefa sɛnea wobetumi anya bi ho

Sɛ wode navs redi dwuma de ama navigation bar a, hwɛ hu sɛ wode a bɛka role="navigation"ɔwofo container a ntease wom sen biara a ɛwɔ <ul>, anaasɛ fa <nav>element bi kyekyere navigation no nyinaa ho. Mfa dwuma no nka <ul>n’ankasa ho, efisɛ eyi remma mfiridwuma a ɛboa no rentumi mfa ho dawuru sɛ ɛyɛ din ankasa.

Hyɛ no nsow sɛ ɛnsɛ sɛ wɔde navigation bars, mpo sɛ wɔayɛ no aniwa so sɛ tabs ne .nav-tabsclass no a, ɛnsɛ wɔde role="tablist", role="tab"anaasɛ role="tabpanel"attributes ma. Eyinom fata ma tabbed interfaces a ɛyɛ nnam nkutoo, sɛnea wɔakyerɛkyerɛ mu wɔ ARIA Authoring Practices Guide tabs pattern . Hwɛ JavaScript suban ma dynamic tabbed interfaces wɔ ɔfa yi mu ma nhwɛso. Attribute no aria-currentho nhia wɔ dynamic tabbed interfaces so efisɛ yɛn JavaScript no di tebea a wɔapaw no ho dwuma denam ka ho aria-selected="true"wɔ active tab no so.

Sɛ wode nsɛm a wɔde gu fam di dwuma

Fa menu ahorow a ɛwɔ fam no ka ho a HTML kakra aka ho ne JavaScript plugin a ɛwɔ fam no .

Tabs a ɛwɔ dropdown ahorow

html na ɛwɔ hɔ
<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>

Nnuru a wɔde gu mu a wɔde gu fam

html na ɛwɔ hɔ
<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 a ɛwɔ hɔ no

Nneɛma a Ɛsakra

Wɔde aka ho wɔ v5.2.0 mu

Sɛ́ Bootstrap CSS nsakrae kwan a ɛrekɔ so no fã no, navs mprempren de mpɔtam hɔ CSS nsakrae ahorow di dwuma wɔ .nav, .nav-tabs, ne .nav-pillsma bere ankasa mu nsakrae a ɛkɔ anim. Wɔde Sass so ahyɛ CSS nsakraeɛ no botaeɛ, enti Sass nhyehyɛɛ no ​​da so ara boa, nso.

.navbase class no so no:

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

.nav-tabsmodifier adesuakuw no so:

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

.nav-pillsmodifier adesuakuw no so:

  --#{$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 nsakrae ahorow

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

JavaScript nneyɛe

Fa tab JavaScript plugin no di dwuma—fa ka ho mmiako mmiako anaa fa bootstrap.jsfael a wɔaboaboa ano no so—na trɛw yɛn navigational tabs ne pills no mu ma yɛ tabbable panes a ɛwɔ mpɔtam hɔ nsɛm no mu.

Eyi yɛ beae bi a ɛwɔ Home tab no mu nsɛm a ɛfa ho. Sɛ wobɔ tab foforo so a, ɛbɛma woatumi ahu eyi ama nea edi hɔ no. Tab no JavaScript sesa adesua ahorow de hwɛ nsɛm a ɛwɔ mu no hu ne sɛnea wɔyɛ no so. Wubetumi de adi dwuma ne tabs, pills, ne .navnavigation foforo biara a -powered.

Eyi yɛ beae bi a ɛwɔ Profile tab no mu nsɛm a ɛfa ho. Sɛ wobɔ tab foforo so a, ɛbɛma woatumi ahu eyi ama nea edi hɔ no. Tab no JavaScript sesa adesua ahorow de hwɛ nsɛm a ɛwɔ mu no hu ne sɛnea wɔyɛ no so. Wubetumi de adi dwuma ne tabs, pills, ne .navnavigation foforo biara a -powered.

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>

Sɛnea ɛbɛyɛ a ɛbɛboa ma ɛne w’ahiade ahyia no, eyi de <ul>-based markup yɛ adwuma, sɛnea wɔakyerɛ wɔ atifi hɔ no, anaasɛ “roll your own” markup biara a wopɛ. Hyɛ no nsow sɛ sɛ wode redi dwuma <nav>a, ɛnsɛ sɛ wode ka ho role="tablist"tẽẽ, efisɛ eyi bɛbu element no kurom dwumadi sɛ akwantu agyiraehyɛde no so. Mmom no, dan kɔ element foforo bi so (wɔ nhwɛso a ɛwɔ ase ha no mu no, a simple <div>) na fa kyekyere <nav>ho.

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

Tabs plugin no nso ne pills yɛ adwuma.

Eyi yɛ beae bi a ɛwɔ Home tab no mu nsɛm a ɛfa ho. Sɛ wobɔ tab foforo so a, ɛbɛma woatumi ahu eyi ama nea edi hɔ no. Tab no JavaScript sesa adesua ahorow de hwɛ nsɛm a ɛwɔ mu no hu ne sɛnea wɔyɛ no so. Wubetumi de adi dwuma ne tabs, pills, ne .navnavigation foforo biara a -powered.

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>

Na ɛne nnuru a wɔde di dwuma gyina hɔ. Sɛnea ɛbɛyɛ yiye no, wɔ vertical tabs ho no, ɛsɛ sɛ wode ka aria-orientation="vertical"tab list container no nso ho.

Eyi yɛ beae bi a ɛwɔ Home tab no mu nsɛm a ɛfa ho. Sɛ wobɔ tab foforo so a, ɛbɛma woatumi ahu eyi ama nea edi hɔ no. Tab no JavaScript sesa adesua ahorow de hwɛ nsɛm a ɛwɔ mu no hu ne sɛnea wɔyɛ no so. Wubetumi de adi dwuma ne tabs, pills, ne .navnavigation foforo biara a -powered.

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>

Nneɛma a wotumi nya

Dynamic tabbed interfaces, sɛnea wɔaka ho asɛm wɔ ARIA Authoring Practices Guide tabs pattern , hwehwɛ role="tablist", role="tab", role="tabpanel", ne aria-su afoforo sɛnea ɛbɛyɛ a wɔde wɔn nhyehyɛe, dwumadie, ne mprempren tebea bɛma wɔn a wɔde mfiridwuma a ɛboa (te sɛ screen readers) di dwuma no. Sɛ́ adeyɛ a eye sen biara no, yɛkamfo kyerɛ sɛ fa <button>elements di dwuma ma tabs no, efisɛ eyinom yɛ controls a ɛkanyan nsakrae a ɛyɛ nnam, sen sɛ wode link ahorow a ɛkɔ krataafa anaa beae foforo so.

Nea ɛne ARIA Authoring Practices nhyehyɛe no hyia no, tab a ɛreyɛ adwuma mprempren no nkutoo na enya keyboard adwene. Sɛ wɔhyɛ JavaScript plugin no ase a, ɛbɛhyehyɛ tabindex="-1"wɔ tab controls a ɛnyɛ adwuma nyinaa so. Sɛ tab a ɛreyɛ adwuma mprempren no nya focus wie a, cursor keys no ma tab a atwam/a edi hɔ no yɛ adwuma, na plugin no sesa rovingtabindex no sɛnea ɛfata. Nanso, hyɛ no nsow sɛ JavaScript plugin no nkyerɛ nsonsonoe a ɛda horizontal ne vertical tab lists ntam bere a ɛfa cursor key nkitahodi ho no: ɛmfa ho sɛnea tab list no kyerɛ no, cursor a ɛwɔ soro ne benkum no nyinaa kɔ tab a atwam no so, na cursor a ɛwɔ fam ne nifa no kɔ so tab a edi hɔ no.

Mpɛn pii no, sɛnea ɛbɛyɛ a keyboard akwantu bɛyɛ mmerɛw no, wɔkamfo kyerɛ sɛ wobɛma tab panel ahorow no ankasa nso ayɛ nea wotumi de wɔn adwene si so, gye sɛ ade a edi kan a nsɛm a ntease wom wɔ tab panel no mu no yɛ nea wotumi de wɔn adwene si so dedaw. JavaScript plugin no mmɔ mmɔden sɛ ɛbɛdi saa afã yi ho dwuma—baabi a ɛfata no, ɛho behia sɛ woma wo tab panel ahorow no yɛ nea wɔde wɔn adwene si so pefee denam tabindex="0"wo markup no a wode bɛka ho no so.
Tab JavaScript plugin no ntumi mmoa tabbed interfaces a ɛwɔ dropdown menus, efisɛ eyinom de nsɛm a ɛfa dwumadie ne kwan a wɔfa so kɔ hɔ nyinaa ba. Sɛ yɛhwɛ sɛnea wobetumi de adi dwuma a, nokwasɛm a ɛyɛ sɛ tab a wɔada no adi mprempren no trigger element no ntumi nhu ntɛm ara (sɛnea ɛwɔ dropdown menu a wɔato mu no mu) no betumi ama adwene atu afra. Sɛ yɛhwɛ kwan a wɔfa so kɔ hɔ a, mprempren ɔkwan biara nni hɔ a ntease wom a wɔbɛfa so ayɛ saa ɔdansi yi ho mfonini akɔ WAI ARIA nhyehyɛe a ɛwɔ hɔ no so, a ɛkyerɛ sɛ ɛnyɛ mmerɛw sɛ wɔbɛma wɔn a wɔde mfiridwuma a ɛboa di dwuma no ate ase.

Data su ahorow a wɔde bedi dwuma

Wubetumi ama tab anaa pill navigation ayɛ adwuma a worenkyerɛw JavaScript biara denam element bi a wobɛkyerɛ ara kwa data-bs-toggle="tab"anaasɛ wobɛka so. data-bs-toggle="pill"Fa saa data su ahorow yi di dwuma wɔ .nav-tabsanaa .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>

Ɛdenam JavaScript so

Ma tabable tabs no nyɛ adwuma denam JavaScript so (ɛsɛ sɛ wode tab biara yɛ adwuma mmiako mmiako):

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

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

Wubetumi ayɛ tab ankorankoro adwuma wɔ akwan horow pii so:

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 nkɛntɛnso

Sɛ wopɛ sɛ tab ahorow no bɛyera a, fa ka .fadeemu biara ho .tab-pane. Ɛsɛ sɛ tab pane a edi kan no nso .showma nsɛm a edi kan no da adi.

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

Akwan a wɔfa so yɛ

Asynchronous akwan ne nsakrae ahorow

API akwan nyinaa yɛ asynchronous na ɛhyɛ nsakrae ase . Wɔsan kɔ nea ɔfrɛɛ no ​​no nkyɛn bere a wɔafi nsakrae no ase ara pɛ nanso ansa na aba awiei . Bio nso, wobebu ani agu ɔkwan a wɔfa so frɛ ade bi a ɛresakra so no so .

Hwɛ yɛn JavaScript nkrataa no na woanya nsɛm pii .

Ɛma wo nsɛm no yɛ adwuma sɛ tab element.

Wubetumi de constructor no ayɛ tab instance, sɛ nhwɛso no:

const bsTab = new bootstrap.Tab('#myTab')
Ɔkwan Nkyerɛmu
dispose Ɔsɛe element bi tab no.
getInstance Static kwan a ɛma wo kwan ma wo nya tab instance a ɛbata DOM element bi ho, wubetumi de adi dwuma sɛnea eyi te: bootstrap.Tab.getInstance(element).
getOrCreateInstance Static kwan a ɛsan de tab nhwɛsoɔ a ɛbata DOM element bi ho anaasɛ ɛbɔ foforɔ sɛ ɛba sɛ wɔanhyɛ aseɛ a. Wubetumi de adi dwuma sɛnea eyi te: bootstrap.Tab.getOrCreateInstance(element).
show Paw tab a wɔde ama no na ɛkyerɛ ne pane a ɛbata ho. Tab foforo biara a na wɔadi kan apaw no bɛyɛ nea wɔanpaw na ne pane a ɛbata ho no sie. San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔakyerɛ tab pane no ankasa (kyerɛ sɛ ansa na shown.bs.tabasɛm no asi).

Nsɛm a esisi

Sɛ worekyerɛ tab foforo a, nsɛm a esisi no bɛtow nnidiso nnidiso a edidi so yi:

  1. hide.bs.tab(wɔ tab a ɛreyɛ adwuma mprempren no so)
  2. show.bs.tab(wɔ tab a wɔrebɛkyerɛ no so)
  3. hidden.bs.tab(wɔ active tab a atwam no so no, nea ɛwɔ hide.bs.tabadeyɛ no ho no ara)
  4. shown.bs.tab(wɔ tab a wɔakyerɛ seesei ara a ɛyɛ adwuma foforo no so no, nea ɛwɔ show.bs.tabadeyɛ no ho no ara)

Sɛ na tab biara nni hɔ a ɛyɛ adwuma dedaw a, ɛnde wɔrentow hide.bs.tabne hidden.bs.tabnsɛm a esisi no.

Adeyɛ no su Nkyerɛmu
hide.bs.tab Saa adeyɛ yi tow bere a ɛsɛ sɛ wɔkyerɛ tab foforo (na ɛnam saa kwan yi so no ɛsɛ sɛ wɔde tab a ɛyɛ adwuma a atwam no sie). Fa event.targetne di dwuma event.relatedTargetfa w’ani si tab a ɛreyɛ adwuma mprempren ne tab foforo a ɛrenkyɛ na ɛreyɛ adwuma no so, sɛnea ɛte biara.
hidden.bs.tab Saa adeyɛ yi tow bere a wɔakyerɛ tab foforo akyi (na ɛnam saa kwan yi so no wɔde tab a ɛyɛ adwuma a atwam no asie). Fa event.targetne di dwuma event.relatedTargetfa w’ani si tab a ɛreyɛ adwuma a atwam no ne tab a ɛreyɛ adwuma foforo no so, sɛnea ɛte biara.
show.bs.tab Saa adeyɛ yi tow wɔ tab show so, nanso ansa na wɔakyerɛ tab foforo no. Fa event.targetne di dwuma event.relatedTargetfa w’ani si active tab ne active tab a atwam no so (sɛ ɛwɔ hɔ a) sɛnea ɛte biara.
shown.bs.tab Saa adeyɛ yi tow wɔ tab show so bere a wɔakyerɛ tab bi akyi. Fa event.targetne di dwuma event.relatedTargetfa w’ani si active tab ne active tab a atwam no so (sɛ ɛwɔ hɔ a) sɛnea ɛte biara.
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
})