Navs and tabs
Cov ntaub ntawv thiab cov piv txwv rau kev siv Bootstrap cov khoom siv navigation.
Base nav
Kev taw qhia muaj nyob hauv Bootstrap qhia cov cim dav dav thiab cov qauv, los ntawm cov .nav
chav kawm hauv paus mus rau lub xeev nquag thiab tsis taus. Hloov cov chav kawm hloov pauv hloov ntawm txhua tus qauv.
Lub hauv paus .nav
tivthaiv yog tsim nrog flexbox thiab muab lub hauv paus muaj zog rau kev tsim txhua yam ntawm cov khoom siv navigation. Nws suav nrog qee qhov kev hloov pauv hloov pauv (rau kev ua haujlwm nrog cov npe), qee qhov txuas txuas rau thaj chaw loj dua, thiab cov qauv kev tsis taus yooj yim.
Lub hauv paus .nav
tivthaiv tsis suav nrog ib .active
lub xeev. Cov piv txwv hauv qab no suav nrog cov chav kawm, feem ntau yog ua kom pom tias chav kawm tshwj xeeb no tsis ua rau muaj qhov tshwj xeeb styling.
Txhawm rau qhia lub xeev nquag mus rau kev pabcuam thev naus laus zis, siv tus aria-current
cwj pwm - siv tus page
nqi rau nplooj ntawv tam sim no, lossis true
rau cov khoom tam sim no hauv ib txheej.
<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>
Cov chav kawm yog siv thoob plaws, yog li koj cov ntawv cim tuaj yeem hloov pauv tau yooj yim. Siv <ul>
s zoo li saum toj no, <ol>
yog tias qhov kev txiav txim ntawm koj cov khoom tseem ceeb, los yog yob koj tus kheej nrog ib lub <nav>
caij. Vim tias kev .nav
siv display: flex
, cov kev sib txuas nav ua tib yam li cov khoom siv nav, tab sis tsis muaj qhov cim ntxiv.
<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>
Muaj cov qauv
Hloov cov style ntawm .nav
s tivthaiv nrog kev hloov kho thiab kev siv hluav taws xob. Sib tov thiab phim raws li xav tau, lossis tsim koj tus kheej.
Kab rov tav alignment
Hloov cov kab rov tav txoj kab nruab nrab ntawm koj lub nav nrog flexbox utilities . Los ntawm lub neej ntawd, navs yog sab laug, tab sis koj tuaj yeem hloov tau yooj yim rau nruab nrab lossis sab xis.
Centered nrog .justify-content-center
:
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
Right-aligned nrog .justify-content-end
:
<ul class="nav justify-content-end">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
Ntsug
Muab koj cov kev taw qhia los ntawm kev hloov cov khoom flex kev taw qhia nrog cov .flex-column
khoom siv hluav taws xob. Yuav tsum tau muab lawv tso rau ntawm qee qhov chaw saib tab sis tsis yog lwm tus? Siv cov lus teb versions (piv txwv li, .flex-sm-column
).
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
Raws li ib txwm muaj, ntsug navigation yog ua tau yam tsis muaj <ul>
s, ib yam nkaus.
<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
Siv qhov yooj yim nav los ntawm saum toj no thiab ntxiv cov .nav-tabs
chav kawm los tsim ib lub tabbed interface. Siv lawv los tsim cov cheeb tsam tabbable nrog peb tab JavaScript plugin .
<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>
Cov tshuaj
Siv tib yam HTML, tab sis siv .nav-pills
hloov:
<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>
Sau thiab ua pov thawj
quab yuam koj .nav
cov ntsiab lus txuas ntxiv qhov dav muaj nyob hauv ib qho ntawm ob chav hloov kho. Yuav kom proportionately sau tag nrho cov chaw muaj nrog koj .nav-item
s, siv .nav-fill
. Daim ntawv ceeb toom tias txhua qhov chaw kab rov tav yog nyob, tab sis tsis yog txhua qhov khoom nav muaj qhov dav tib yam.
<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>
Thaum siv ib <nav>
-raws li kev taw qhia, koj tuaj yeem ua kom nyab xeeb tshem tawm .nav-item
raws li tsuas .nav-link
yog xav tau rau cov ntsiab lus styling <a>
.
<nav class="nav nav-pills nav-fill">
<a class="nav-link active" aria-current="page" href="#">Active</a>
<a class="nav-link" href="#">Much longer nav link</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link disabled">Disabled</a>
</nav>
Rau qhov sib npaug-dav, siv .nav-justified
. Txhua qhov chaw kab rov tav yuav nyob ntawm qhov txuas nav, tab sis tsis zoo li cov .nav-fill
saum toj no, txhua yam khoom nav yuav yog tib qhov dav.
<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>
Zoo ib yam li qhov .nav-fill
piv txwv uas siv ib <nav>
-based navigation.
<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>
Ua haujlwm nrog flex utilities
Yog tias koj xav tau cov kev hloov pauv hloov pauv, xav txog kev siv cov khoom siv hluav taws xob flexbox . Thaum hais lus ntau dua, cov khoom siv no muab kev hloov kho ntau dua hla cov ntsiab lus teb. Hauv qhov piv txwv hauv qab no, peb cov nav hia yuav muab tso rau ntawm qhov chaw qis tshaj plaws, tom qab ntawd hloov mus rau kab rov tav layout uas sau qhov dav muaj pib los ntawm qhov chaw me me.
<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>
Hais txog kev siv tau
Yog tias koj siv navs los muab lub bar navigation, nco ntsoov ntxiv ib qho role="navigation"
rau lub thawv niam txiv lub ntsiab lus tshaj plaws ntawm <ul>
, lossis qhwv ib lub <nav>
caij nyob ib ncig ntawm tag nrho cov navigation. Tsis txhob ntxiv lub luag haujlwm rau <ul>
nws tus kheej, vim qhov no yuav tiv thaiv nws los ntawm kev tshaj tawm raws li cov npe tiag tiag los ntawm kev pabcuam thev naus laus zis.
Nco ntsoov tias cov bars navigation, txawm tias pom kev zoo li tabs nrog cov .nav-tabs
chav kawm, yuav tsum tsis txhob muab role="tablist"
, role="tab"
lossis role="tabpanel"
cov cwj pwm. Cov no tsuas yog tsim nyog rau dynamic tabbed interfaces, raws li tau piav qhia hauv WAI ARIA Authoring Practices . Saib JavaScript tus cwj pwm rau dynamic tabbed interfaces hauv seem no piv txwv. Tus aria-current
cwj pwm tsis tsim nyog ntawm dynamic tabbed interfaces txij li peb JavaScript tswj hwm lub xeev xaiv los ntawm kev ntxiv aria-selected="true"
rau ntawm lub tab nquag.
Siv cov dropdowns
Ntxiv dropdown menus nrog me ntsis ntxiv HTML thiab dropdowns JavaScript plugin .
Tabs nrog dropdowns
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Active</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
Cov tshuaj nrog dropdowns
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Active</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
Sass
Hloov pauv
$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 cwj pwm
Siv lub tab JavaScript plugin - suav nrog nws tus kheej lossis los ntawm cov ntaub ntawv sau ua ke bootstrap.js
- txhawm rau txuas ntxiv peb cov tab thiab cov ntsiav tshuaj los tsim cov tabbable panes ntawm cov ntsiab lus hauv zos.
Dynamic tabbed interfaces, raws li tau piav qhia hauv WAI ARIA Authoring Practices , xav tau role="tablist"
, role="tab"
, role="tabpanel"
, thiab cov aria-
cwj pwm ntxiv txhawm rau txhawm rau nthuav qhia lawv cov qauv, kev ua haujlwm thiab lub xeev tam sim no rau cov neeg siv cov thev naus laus zis pab (xws li cov nyeem ntawv tshuaj ntsuam). Raws li qhov kev coj ua zoo tshaj plaws, peb pom zoo kom siv <button>
cov ntsiab lus rau cov tabs, vim tias cov no yog cov kev tswj hwm uas ua rau muaj kev hloov pauv hloov pauv, tsis yog cov txuas uas mus rau nplooj ntawv tshiab lossis qhov chaw.
Nco ntsoov tias dynamic tabbed interfaces yuav tsum tsis muaj dropdown menus, vim qhov no ua rau ob qho tib si usability thiab accessibility teeb meem. Los ntawm kev pom kev siv tau, qhov tseeb tias tam sim no tab tom nthuav tawm lub ntsiab lus tsis pom tam sim ntawd (raws li nws nyob hauv cov ntawv qhia zaub mov kaw) tuaj yeem ua rau tsis meej pem. Los ntawm qhov kev nkag mus tau zoo, tam sim no tsis muaj txoj hauv kev zoo los piav qhia qhov kev tsim kho no rau tus qauv WAI ARIA tus qauv, txhais tau tias nws tsis tuaj yeem nkag siab yooj yim rau cov neeg siv cov cuab yeej pabcuam.
Nov yog qee qhov chaw muab cov ntsiab lus hauv Tsev tab cov ntsiab lus cuam tshuam. Nyem rau lwm tab yuav toggle qhov pom ntawm qhov no rau lwm qhov. Lub tab JavaScript swaps chav kawm los tswj cov ntsiab lus pom pom thiab styling. Koj tuaj yeem siv nws nrog tabs, ntsiav tshuaj, thiab lwm yam .nav
-powered navigation.
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>
Txhawm rau pab kom haum koj cov kev xav tau, qhov no ua haujlwm nrog <ul>
-based markup, raws li qhia saum toj no, lossis nrog kev txiav txim siab "yob koj tus kheej" markup. Nco ntsoov tias yog tias koj siv <nav>
, koj yuav tsum tsis txhob ntxiv role="tablist"
ncaj qha rau nws, vim qhov no yuav dhau los ntawm lub luag haujlwm ntawm lub luag haujlwm ua ib qho chaw navigation. Hloov chaw, hloov mus rau lwm lub caij (hauv qhov piv txwv hauv qab no, ib qho yooj yim <div>
) thiab qhwv <nav>
ib ncig ntawm nws.
<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 kuj ua haujlwm nrog tshuaj.
Nov yog qee qhov chaw muab cov ntsiab lus hauv Tsev tab cov ntsiab lus cuam tshuam. Nyem rau lwm tab yuav toggle qhov pom ntawm qhov no rau lwm qhov. Lub tab JavaScript swaps chav kawm los tswj cov ntsiab lus pom pom thiab styling. Koj tuaj yeem siv nws nrog tabs, ntsiav tshuaj, thiab lwm yam .nav
-powered navigation.
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>
Thiab nrog cov tshuaj ntsug.
Nov yog qee qhov chaw muab cov ntsiab lus hauv Tsev tab cov ntsiab lus cuam tshuam. Nyem rau lwm tab yuav toggle qhov pom ntawm qhov no rau lwm qhov. Lub tab JavaScript swaps chav kawm los tswj cov ntsiab lus pom pom thiab styling. Koj tuaj yeem siv nws nrog tabs, ntsiav tshuaj, thiab lwm yam .nav
-powered navigation.
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>
Siv cov ntaub ntawv tus cwj pwm
Koj tuaj yeem qhib lub tab lossis ntsiav tshuaj navigation yam tsis tau sau ib qho JavaScript los ntawm kev qhia yooj yim data-bs-toggle="tab"
lossis data-bs-toggle="pill"
ntawm lub ntsiab lus. Siv cov ntaub ntawv tus cwj pwm ntawm .nav-tabs
lossis .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>
Ntawm JavaScript
Qhib tabbable tabs ntawm JavaScript (txhua tab yuav tsum tau qhib ib tus zuj zus):
var triggerTabList = [].slice.call(document.querySelectorAll('#myTab button'))
triggerTabList.forEach(function (triggerEl) {
var tabTrigger = new bootstrap.Tab(triggerEl)
triggerEl.addEventListener('click', function (event) {
event.preventDefault()
tabTrigger.show()
})
})
Koj tuaj yeem qhib ib tus neeg tab hauv ntau txoj hauv kev:
var triggerEl = document.querySelector('#myTab button[data-bs-target="#profile"]')
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
var triggerFirstTabEl = document.querySelector('#myTab li:first-child button')
bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
Fade nyhuv
Txhawm rau ua kom cov tabs ploj mus, ntxiv .fade
rau txhua qhov .tab-pane
. Thawj tab pane yuav tsum tau .show
ua kom pom cov ntsiab lus thawj zaug.
<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>
Cov txheej txheem
Asynchronous txoj kev thiab kev hloov
Txhua txoj kev API yog asynchronous thiab pib hloov pauv . Lawv rov qab mus rau tus neeg hu xov tooj sai li sai tau thaum qhov kev hloov pauv pib tab sis ua ntej nws xaus . Tsis tas li ntawd, ib txoj kev hu rau ib qho kev hloov pauv yuav raug tsis quav ntsej .
constructor
Activates lub tab element thiab cov ntsiab lus ntim. Tab yuav tsum muaj ib data-bs-target
lossis, yog siv qhov txuas, tus href
cwj pwm, tsom rau lub thawv ntawm DOM.
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="messages-tab" data-bs-toggle="tab" data-bs-target="#messages" type="button" role="tab" aria-controls="messages" aria-selected="false">Messages</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="settings-tab" data-bs-toggle="tab" data-bs-target="#settings" type="button" role="tab" aria-controls="settings" aria-selected="false">Settings</button>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
<div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
<div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
<div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
</div>
<script>
var firstTabEl = document.querySelector('#myTab li:last-child button')
var firstTab = new bootstrap.Tab(firstTabEl)
firstTab.show()
</script>
ua yeeb yam
Xaiv qhov muab tab thiab qhia nws cov kab sib txuas. Lwm lub tab uas tau xaiv yav dhau los yuav tsis raug xaiv thiab nws cov pane cuam tshuam tau muab zais. Rov qab mus rau tus neeg hu ua ntej lub tab pane tau tshwm sim tiag tiag (piv txwv li ua ntej qhov shown.bs.tab
xwm txheej tshwm sim).
var someTabTriggerEl = document.querySelector('#someTabTrigger')
var tab = new bootstrap.Tab(someTabTriggerEl)
tab.show()
pov tseg
Ua kom puas lub ntsiab tab.
getInstance
Txoj kev zoo li qub uas tso cai rau koj kom tau txais tab piv txwv cuam tshuam nrog DOM lub caij
var triggerEl = document.querySelector('#trigger')
var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance
getOrCreateInstance
Txoj kev zoo li qub uas tso cai rau koj kom tau txais tab piv txwv cuam tshuam nrog DOM lub caij, lossis tsim ib qho tshiab yog tias nws tsis tau pib
var triggerEl = document.querySelector('#trigger')
var tab = bootstrap.Tab.getOrCreateInstance(triggerEl) // Returns a Bootstrap tab instance
Cov xwm txheej
Thaum pom ib lub tab tshiab, cov xwm txheej hluav taws kub hauv qhov kev txiav txim hauv qab no:
hide.bs.tab
(ntawm lub tab active tam sim no)show.bs.tab
(ntawm qhov yuav tsum tau qhia tab)hidden.bs.tab
(nyob rau yav dhau los active tab, tib yam li rau qhovhide.bs.tab
kev tshwm sim)shown.bs.tab
(ntawm lub tab tshiab uas nyuam qhuav tshwm sim, tib yam li rau qhovshow.bs.tab
kev tshwm sim)
Yog tias tsis muaj tab twb ua haujlwm lawm, ces cov xwm txheej hide.bs.tab
thiab hidden.bs.tab
cov xwm txheej yuav tsis raug rho tawm haujlwm.
Hom xwm txheej | Kev piav qhia |
---|---|
show.bs.tab |
Qhov kev tshwm sim no tua hluav taws ntawm tab qhia, tab sis ua ntej tab tshiab tau tshwm sim. Siv event.target thiab event.relatedTarget tsom rau lub tab active thiab yav dhau los active tab (yog tias muaj) feem. |
shown.bs.tab |
Qhov kev tshwm sim no tua hluav taws ntawm tab qhia tom qab tau pom tab. Siv event.target thiab event.relatedTarget tsom rau lub tab active thiab yav dhau los active tab (yog tias muaj) feem. |
hide.bs.tab |
Qhov kev tshwm sim no tua hluav taws thaum lub tab tshiab yuav tsum tau tshwm sim (thiab yog li lub tab yav dhau los yuav tsum tau muab zais). Siv event.target thiab event.relatedTarget tsom rau cov tab tam sim no thiab cov tshiab sai sai-rau-yuav-ua haujlwm tab, feem. |
hidden.bs.tab |
Qhov kev tshwm sim no tshwm sim tom qab lub tab tshiab tau tshwm sim (thiab yog li lub tab active yav dhau los tau muab zais). Siv event.target thiab event.relatedTarget tsom mus rau lub tab active yav dhau los thiab cov tshiab tab tshiab, raws li. |
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
})