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 .nav
class no so kosi active ne disabled states so. Sesa modifier classes na dannan style biara ntam.
Wɔde flexbox na ɛkyekyee base .nav
component 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 .nav
component no nka .active
tebea 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-current
su no di dwuma — fa page
bo a ɛsom no di dwuma ma krataafa a ɛwɔ hɔ mprempren, anaasɛ true
ade a ɛwɔ hɔ mprempren wɔ nhyehyɛe bi mu.
<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" href="#" tabindex="-1" aria-disabled="true">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ɛ .nav
uses display: flex
, nav links no yɛ wɔn ade sɛnea nav nneɛma bɛyɛ no, nanso enni markup foforo no.
<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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</nav>
Nneɛma a wɔde yɛ nneɛma a ɛwɔ hɔ
Sesa .nav
s 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
: .
<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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
Nifa-a ɛne .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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
Tenten mu
Stack wo navigation denam nsakrae a wobɛsesa flex ade no kwankyerɛ ne .flex-column
utility 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
).
<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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
Sɛnea ɛte daa no, vertical navigation betumi ayɛ yiye a <ul>
s nka ho, nso.
<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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</nav>
Tab ahorow
Fa nav titiriw no fi soro na ɔde .nav-tabs
adesuakuw no ka ho ma ɛyɛ tabbed interface. Fa wɔn yɛ tabbable regions denam yɛn tab JavaScript plugin no so .
<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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
Nnuru a wɔde di dwuma
Fa saa HTML koro no ara, nanso fa di dwuma .nav-pills
mmom:
<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" href="#" tabindex="-1" aria-disabled="true">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-item
s 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ɛ.
<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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
Sɛ wode <nav>
-based navigation redi dwuma a, wubetumi ayi afi mu dwoodwoo .nav-item
sɛnea .nav-link
ɛho hia ma styling <a>
elements nkutoo.
<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" href="#" tabindex="-1" aria-disabled="true">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-fill
atifi hɔ no, nav adeɛ biara bɛyɛ ne tɛtrɛtɛ korɔ.
<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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
Te sɛ .nav-fill
nhwɛso a wɔde <nav>
-gyina akwantuo so di dwuma no.
<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" href="#" tabindex="-1" aria-disabled="true">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.
<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" href="#" tabindex="-1" aria-disabled="true">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-tabs
class no a, ɛnsɛ sɛ wɔde role="tablist"
, role="tab"
anaasɛ role="tabpanel"
attributes ma. Eyinom fata ma tabbed interfaces a ɛyɛ nnam nkutoo, sɛnea wɔaka ho asɛm wɔ WAI ARIA Authoring Practices . Hwɛ JavaScript suban ma dynamic tabbed interfaces wɔ ɔfa yi mu ma nhwɛso. Attribute no aria-current
ho 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 nneɛma 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
<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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
Nnuru a wɔde gu mu a wɔde gu fam
<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" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
Sass
Nneɛma a Ɛsakra
$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;
JavaScript nneyɛe
Fa tab JavaScript plugin no di dwuma—fa ka ho mmiako mmiako anaa fa bootstrap.js
fael 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.
Dynamic tabbed interfaces, sɛnea wɔaka ho asɛm wɔ WAI ARIA Authoring Practices , 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.
Hyɛ no nsow sɛ ɛnsɛ sɛ dynamic tabbed interfaces no kura dropdown menus, efisɛ eyi 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.
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 .nav
navigation 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.
<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>
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>
</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>
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 .nav
navigation 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.
<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>
Na ɛne nnuru a wɔde di dwuma gyina hɔ.
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 .nav
navigation 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 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>
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-tabs
anaa .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>
Ɛdenam JavaScript so
Ma tabbable tabs no nyɛ adwuma denam JavaScript so (ɛsɛ sɛ wode tab biara yɛ adwuma mmiako mmiako):
var triggerTabList = [].slice.call(document.querySelectorAll('#myTab a'))
triggerTabList.forEach(function (triggerEl) {
var tabTrigger = new bootstrap.Tab(triggerEl)
triggerEl.addEventListener('click', function (event) {
event.preventDefault()
tabTrigger.show()
})
})
Wubetumi ayɛ tab ankorankoro adwuma wɔ akwan horow pii so:
var triggerEl = document.querySelector('#myTab a[href="#profile"]')
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
var triggerFirstTabEl = document.querySelector('#myTab li:first-child a')
bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
Fade nkɛntɛnso
Sɛ wopɛ sɛ tab ahorow no bɛyera a, fa ka .fade
emu biara ho .tab-pane
. Ɛsɛ sɛ tab pane a edi kan no nso .show
ma 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">...</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>
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 . Nea ɛka ho no, wobebu ani agu ɔkwan a wɔfa so frɛ ade bi a ɛrekɔ so no so .
constructor
Ɛma tab element ne nsɛm a ɛwɔ mu no yɛ adwuma. Ɛsɛ sɛ tab nya data-bs-target
anaa, sɛ wode link redi dwuma a, href
attribute, a ɛde n’ani si container node so wɔ DOM no mu.
<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 a')
var firstTab = new bootstrap.Tab(firstTabEl)
firstTab.show()
</script>
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.tab
asɛm no asi).
var someTabTriggerEl = document.querySelector('#someTabTrigger')
var tab = new bootstrap.Tab(someTabTriggerEl)
tab.show()
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
var triggerEl = document.querySelector('#trigger')
var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance
getOrCreateInstance
Static kwan a ɛma wo kwan ma wo nya tab instance a ɛbata DOM element bi ho, anaasɛ wobɔ foforo sɛ ɛba sɛ wɔanhyɛ aseɛ a
var triggerEl = document.querySelector('#trigger')
var tab = bootstrap.Tab.getOrCreateInstance(triggerEl) // Returns a Bootstrap tab instance
Events
Sɛ worekyerɛ tab foforo a, nsɛm a esisi no bɛtow nnidiso nnidiso a edidi so yi:
hide.bs.tab
(wɔ tab a ɛreyɛ adwuma mprempren no so)show.bs.tab
(wɔ tab a wɔrebɛkyerɛ no so)hidden.bs.tab
(wɔ active tab a atwam no so no, nea ɛwɔhide.bs.tab
adeyɛ no ho no ara)shown.bs.tab
(wɔ tab a wɔakyerɛ seesei ara a ɛyɛ adwuma foforo no so no, nea ɛwɔshow.bs.tab
adeyɛ no ho no ara)
Sɛ na tab biara nni hɔ a ɛyɛ adwuma dedaw a, ɛnde wɔrentow hide.bs.tab
ne hidden.bs.tab
nsɛm a esisi no.
Adeyɛ no su | Nkyerɛmu |
---|---|
show.bs.tab |
Saa adeyɛ yi tow wɔ tab show so, nanso ansa na wɔakyerɛ tab foforo no. Fa di dwumaevent.target ne di dwuma event.relatedTarget fa 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 di dwumaevent.target ne di dwuma event.relatedTarget fa w’ani si active tab ne active tab a atwam no so (sɛ ɛwɔ hɔ a) sɛnea ɛte biara. |
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 di dwumaevent.target ne di dwuma event.relatedTarget fa 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 di dwuma event.target neevent.relatedTarget di dwuma fa w’ani si tab a ɛreyɛ adwuma a atwam no ne tab a ɛreyɛ adwuma foforo no so, sɛnea ɛte biara. |
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
})