Navs
Dokuméntasi sareng conto kumaha cara ngagunakeun komponén navigasi anu kalebet Bootstrap.
Napigasi sadia dina Bootstrap babagi markup umum jeung gaya, ti .nav
kelas dasar ka nagara aktip tur ditumpurkeun. Swap kelas modifier pikeun pindah antara unggal gaya.
Komponén dasarna .nav
diwangun ku flexbox sareng nyayogikeun pondasi anu kuat pikeun ngawangun sadaya jinis komponén navigasi. Ieu ngawengku sababaraha overrides gaya (pikeun gawé bareng béréndélan), sababaraha padding link pikeun wewengkon hit nu leuwih gede, sarta styling ditumpurkeun dasar.
Komponén dasar .nav
henteu kalebet kaayaan naon waé .active
. Conto di handap ieu kalebet kelas, utamina pikeun nunjukkeun yén kelas khusus ieu henteu micu gaya khusus.
<ul class="nav">
<li class="nav-item">
<a class="nav-link active" 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="#">Disabled</a>
</li>
</ul>
Kelas dianggo sapanjang, janten markup anjeun tiasa super fleksibel. Paké <ul>
s kawas di luhur, atawa gulung sorangan kalawan nyebutkeun <nav>
unsur. Kusabab .nav
kagunaan display: flex
, Tumbu nav kalakuanana sarua jeung item nav ngalakukeunana, tapi tanpa markup tambahan.
<nav class="nav">
<a class="nav-link active" href="#">Active</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link disabled" href="#">Disabled</a>
</nav>
Ngarobah gaya .nav
komponén s kalawan modifiers na Utiliti. Campur jeung cocog sakumaha diperlukeun, atawa ngawangun sorangan.
Ngarobah alignment horizontal nav anjeun kalawan flexbox utiliti . Sacara standar, navs téh kénca-Blok, tapi anjeun bisa kalayan gampang ngarobahna kana puseur atawa katuhu Blok.
Dipuseurkeun ku .justify-content-center
:
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" 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="#">Disabled</a>
</li>
</ul>
Blok katuhu jeung .justify-content-end
:
<ul class="nav justify-content-end">
<li class="nav-item">
<a class="nav-link active" 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="#">Disabled</a>
</li>
</ul>
Tumpukan navigasi anjeun ku cara ngarobah arah item fleksibel sareng .flex-column
utilitas. Kudu tumpukan aranjeunna dina sababaraha viewports tapi teu batur? Paké versi responsif (misalna, .flex-sm-column
).
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" 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="#">Disabled</a>
</li>
</ul>
Sakumaha biasa, navigasi nangtung mungkin tanpa <ul>
s, teuing.
<nav class="nav flex-column">
<a class="nav-link active" href="#">Active</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link disabled" href="#">Disabled</a>
</nav>
Nyokot nav dasar ti luhur tur nambahkeun .nav-tabs
kelas pikeun ngahasilkeun panganteur tabbed. Anggo aranjeunna pikeun nyiptakeun daérah tabable sareng plugin JavaScript tab kami .
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" 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="#">Disabled</a>
</li>
</ul>
Candak HTML anu sami, tapi nganggo .nav-pills
:
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" 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="#">Disabled</a>
</li>
</ul>
Maksakeun .nav
eusi Anjeun pikeun manjangkeun lebar sadia pinuh salah sahiji dua kelas modifier. Pikeun saimbang ngeusian sakabeh spasi sadia kalawan .nav-item
s anjeun, make .nav-fill
. Perhatikeun yén sakabéh spasi horizontal nempatan, tapi teu unggal item nav boga lebar sarua.
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">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="#">Disabled</a>
</li>
</ul>
Lamun maké <nav>
navigasi -based, pastikeun pikeun kaasup .nav-item
dina jangkar.
<nav class="nav nav-pills nav-fill">
<a class="nav-item nav-link active" href="#">Active</a>
<a class="nav-item nav-link" href="#">Link</a>
<a class="nav-item nav-link" href="#">Link</a>
<a class="nav-item nav-link disabled" href="#">Disabled</a>
</nav>
Pikeun elemen sarua-lebar, make .nav-justified
. Kabéh spasi horizontal bakal dikawasaan ku Tumbu nav, tapi teu saperti di .nav-fill
luhur, unggal item nav bakal lebar sarua.
<nav class="nav nav-pills nav-justified">
<a class="nav-link active" href="#">Active</a>
<a class="nav-link" href="#">Longer nav link</a>
<a class="nav-link" href="#">Link</a>
<a class="nav-link disabled" href="#">Disabled</a>
</nav>
Sarupa jeung .nav-fill
conto ngagunakeun <nav>
navigasi -based, pastikeun kaasup .nav-item
dina jangkar.
<nav class="nav nav-pills nav-justified">
<a class="nav-item nav-link active" href="#">Active</a>
<a class="nav-item nav-link" href="#">Link</a>
<a class="nav-item nav-link" href="#">Link</a>
<a class="nav-item nav-link disabled" href="#">Disabled</a>
</nav>
Lamun perlu variasi nav responsif, mertimbangkeun ngagunakeun runtuyan flexbox Utiliti . Sanaos langkung verbose, utilitas ieu nawiskeun kustomisasi anu langkung ageung dina titik putus responsif. Dina conto di handap, nav kami bakal tumpuk dina breakpoint panghandapna, lajeng adaptasi jeung perenah horizontal nu ngeusi lebar sadia mimitian ti breakpoint leutik.
<nav class="nav nav-pills flex-column flex-sm-row">
<a class="flex-sm-fill text-sm-center nav-link active" href="#">Active</a>
<a class="flex-sm-fill text-sm-center nav-link" href="#">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="#">Disabled</a>
</nav>
Upami Anjeun keur make navs nyadiakeun bar navigasi, pastikeun pikeun nambahkeun a role="navigation"
kana wadahna indungna paling logis tina <ul>
, atawa mungkus <nav>
unsur sabudeureun sakabéh navigasi. Entong nambihan peran ka <ul>
dirina, sabab ieu bakal nyegah diumumkeun salaku daptar aktual ku téknologi anu ngabantosan.
Catet yén bar navigasi, sanajan sacara visual ditataan salaku tab jeung .nav-tabs
kelas, teu kudu dibikeun role="tablist"
, role="tab"
atawa role="tabpanel"
atribut. Ieu ngan cocog pikeun panganteur tab dinamis, sakumaha dijelaskeun dina Praktek Pangarang WAI ARIA . Tingali paripolah JavaScript pikeun panganteur tab dinamis dina bagian ieu pikeun conto.
Tambihkeun ménu lungsur sareng HTML tambahan sakedik sareng plugin JavaScript dropdowns .
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Paké plugin tab JavaScript-kaasupkeun eta individual atawa ngaliwatan bootstrap.js
file disusun-pikeun manjangkeun tab navigasi urang jeung pil pikeun nyieun panel tabable tina eusi lokal, sanajan ngaliwatan menu dropdown.
Upami anjeun nuju ngawangun JavaScript kami tina sumber, peryogiutil.js
.
Antarmuka tab dinamis, sakumaha anu dijelaskeun dina Praktek Ngarang WAI ARIA , ngabutuhkeun role="tablist"
, role="tab"
, role="tabpanel"
, sareng aria-
atribut tambahan pikeun nepikeun strukturna, fungsionalitas sareng kaayaan ayeuna ka pangguna téknologi anu ngabantosan (sapertos pamiarsa layar).
Catet yén panganteur tab dinamis teu kedah ngandung ménu lungsur, sabab ieu nyababkeun masalah usability sareng aksésibilitas. Tina sudut pandang usability, kanyataan yén unsur pemicu tab anu ayeuna ditampilkeun henteu langsung katingali (sabab aya di jero menu dropdown anu ditutup) tiasa nyababkeun kabingungan. Tina sudut pandang aksésibilitas, ayeuna teu aya cara anu wijaksana pikeun memetakan konstruksi sapertos kieu kana pola WAI ARIA standar, hartosna éta henteu tiasa gampang kaharti ku pangguna téknologi anu ngabantosan.
Denim atah anjeun panginten henteu acan kantos nguping aranjeunna kaos jeans Austin. Nesciunt tahu stumptown aliqua, retro synth master cleanse. Kumis klise tempor, williamsburg carles vegan helvetica. Reprehenderit tukang daging retro keffiyeh dreamcatcher synth. Baju haneut Cosby eu banh mi, qui irure Terry richardson ex cumi. Aliquip nempatkeun salvia cillum iphone. Seitan aliquip quis cardigan apparel Amérika, jagal voluptate nisi qui.
Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.
Pikeun mantuan nyocogkeun ka kabutuhan Anjeun, ieu jalan kalawan <ul>
-based markup, sakumaha ditémbongkeun di luhur, atawa kalayan sagala wenang "gulungkeun sorangan" markup. Catet yén upami anjeun nganggo <nav>
, anjeun henteu kedah nambihan role="tablist"
langsung kana éta, sabab ieu bakal ngaleungitkeun peran asli unsur éta salaku landmark navigasi. Gantina, pindah ka unsur alternatif (dina conto di handap, basajan <div>
) jeung bungkus <nav>
sabudeureun eta.
Plugin tab ogé tiasa dianggo sareng pil.
Consequat occaecat ullamco amet non eiusmod nostrud dolore irure incididunt est duis anim sunt officia. Fugit velit proident aliquip sababaraha incididunt nostrud exercitation proident est nisi. Irure magna elit commodo anim ex veniam culpa eiusmod id nostrud sit cupidatat in veniam ad. Eiusmod consequat eu adipisicing minim anim aliquip cupidatat culpa excepteur quis. Occaecat sit eu exercitation irure Lorem incididunt nostrud.
Ad pariatur nostrud pariatur exercitation ipsum ipsum culpa mollit commodo mollit ex. Aute sunt incididunt amet commodo est sint nisi deserunt pariatur do. Aliquip ex eiusmod voluptate exercitation cillum id incididunt elit sunt. Qui minim sit magna Lorem id et dolore velit Lorem amet exercitation duis deserunt. Anim id labore elit adipisicing ut in id occaecat pariatur ut ullamco ea tempor duis.
Est quis nulla laborum officia ad nisi ex nostrud culpa Lorem excepteur aliquip dolor aliqua irure ex. Nulla ut duis ipsum nisi elit fugiat commodo sunt reprehenderit laborum veniam eu veniam. Eiusmod minim exercitation fugiat irure ex labore incididunt do fugiat commodo aliquip sit id deserunt reprehenderit aliquip nostrud. Amet ex cupidatat excepteur aute veniam incididunt mollit cupidatat esse irure officia elit do ipsum ullamco Lorem. Ullamco ut ad minim do mollit labore ipsum laboris ipsum commodo sunt tempor enim incididunt. Commodo quis sunt dolore aliquip aute tempor irure magna enim minim reprehenderit. Ullamco consectetur culpa veniam sint cillum aliqua incididunt velit ullamco sunt ullamco quis quis commodo voluptate. Mollit nulla nostrud adipisicing aliqua cupidatat aliqua pariatur mollit voluptate voluptate consequat non.
Sareng sareng pil nangtung.
Cillum ad ut irure tempor velit nostrud occaecat ullamco aliqua anim Lorem sint. Veniam sint duis incididunt do esse magna mollit excepteur laborum qui. Id id reprehenderit sit est eu aliqua occaecat quis et velit excepteur laborum mollit dolore eiusmod. Ipsum dolor in occaecat commodo et voluptate minimal reprehenderit mollit pariatur. Deserunt non laborum enim et cillum eu deserunt excepteur ea incididunt minim occaecat.
Culpa dolor voluptate do laboris laboris irure reprehenderit id incididunt duis pariatur mollit aute magna pariatur consectetur. Eu veniam duis non ut dolor deserunt commodo et minim in quis laboris ipsum velit id veniam. Quis ut consectetur adipisicing officia excepteur non sit. Ut et elit aliquip labore Lorem enim eu. Ullamco mollit occaecat dolore ipsum id officia mollit qui esse anim eiusmod do sint minim consectetur qui.
Fugiat id quis dolor culpa eiusmod anim velit excepteur proident dolor aute qui magna. Ad proident laboris ullamco esse anim Lorem Lorem veniam quis Lorem irure occaecat velit nostrud magna nulla. Velit et et proident Lorem do ea tempor officia dolor. Reprehenderit Lorem aliquip labore est magna commodo est ea veniam consectetur.
Eu dolore ea ullamco dolore Lorem id cupidatat excepteur reprehenderit consectetur elit id dolor proident in cupidatat officia. Voluptate excepteur commodo labore nisi cillum duis aliqua do. Aliqua amet qui mollit consectetur nulla mollit velit aliqua veniam nisi id do Lorem deserunt amet. Culpa ullamco sit adipisicing labore officia magna elit nisi in aute tempor commodo eiusmod.
Anjeun tiasa ngaktipkeun navigasi tab atanapi pil tanpa nyerat JavaScript ku ngan saukur nangtukeun data-toggle="tab"
atanapi data-toggle="pill"
dina unsur. Paké atribut data ieu dina .nav-tabs
atawa .nav-pills
.
Aktipkeun tab tabable via JavaScript (unggal tab kudu diaktipkeun individual):
Anjeun tiasa ngaktipkeun tab individu ku sababaraha cara:
To make tabs fade in, add .fade
to each .tab-pane
. The first tab pane must also have .show
to make the initial content visible.
Asynchronous methods and transitions
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
Activates a tab element and content container. Tab should have either a data-target
or an href
targeting a container node in the DOM.
Selects the given tab and shows its associated pane. Any other tab that was previously selected becomes unselected and its associated pane is hidden. Returns to the caller before the tab pane has actually been shown (i.e. before the shown.bs.tab
event occurs).
Destroys an element’s tab.
When showing a new tab, the events fire in the following order:
hide.bs.tab
(on the current active tab)show.bs.tab
(on the to-be-shown tab)hidden.bs.tab
(on the previous active tab, the same one as for thehide.bs.tab
event)shown.bs.tab
(on the newly-active just-shown tab, the same one as for theshow.bs.tab
event)
If no tab was already active, then the hide.bs.tab
and hidden.bs.tab
events will not be fired.
Event Type | Description |
---|---|
show.bs.tab | This event fires on tab show, but before the new tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. |
shown.bs.tab | This event fires on tab show after a tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. |
hide.bs.tab | This event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use event.target and event.relatedTarget to target the current active tab and the new soon-to-be-active tab, respectively. |
hidden.bs.tab | This event fires after a new tab is shown (and thus the previous active tab is hidden). Use event.target and event.relatedTarget to target the previous active tab and the new active tab, respectively. |