Navs
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.
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.
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
:
Right-aligned nrog .justify-content-end
:
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
).
Raws li ib txwm muaj, ntsug navigation yog ua tau yam tsis muaj <ul>
s, ib yam nkaus.
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 .
Cov tshuaj
Siv tib yam HTML, tab sis siv .nav-pills
hloov:
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.
Thaum siv ib <nav>
-raws li navigation, nco ntsoov suav nrog .nav-item
rau cov thauj tog rau nkoj.
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.
Zoo ib yam li qhov .nav-fill
piv txwv uas siv ib <nav>
-raws li navigation, nco ntsoov suav nrog .nav-item
rau ntawm cov thauj tog rau nkoj.
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.
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.
Siv cov dropdowns
Ntxiv dropdown menus nrog me ntsis ntxiv HTML thiab dropdowns JavaScript plugin .
Tabs nrog dropdowns
Cov tshuaj nrog dropdowns
JavaScript cwj pwm
Siv lub tab JavaScript plugin - suav nrog nws tus kheej lossis los ntawm cov ntaub ntawv muab tso ua ke bootstrap.js
- txhawm rau txuas ntxiv peb cov ntawv qhia navigational thiab tshuaj los tsim cov tabbable panes ntawm cov ntsiab lus hauv zos, txawm tias dhau ntawm cov ntawv teev npe.
Yog tias koj tab tom tsim peb JavaScript los ntawm qhov chaw, nws xav tauutil.js
.
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).
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.
Raw denim tej zaum koj tsis tau hnov txog lawv cov ris tsho luv Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit neeg tua tsiaj retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, neeg tua tsiaj 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.
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.
Tabs plugin kuj ua haujlwm nrog tshuaj.
Consequat occaecat ullamco amet non eiusmod nostrud dolore irure incididunt est duis anim sunt officia. Fugiat velit proident aliquip nisi incididunt nostrud exercitation proident yog 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 zaum 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.
Thiab nrog cov tshuaj ntsug.
Cillum ad ut irure tempor velit nostrud occaecat ullamco aliqua anim Lorem sint. Veniam sint duis incididunt do esse magna mollit excepteur lab qui. Id id reprehenderit zaum est eu aliqua occaecat quis et velit excepteur laborum mollit dolore eiusmod. Ipsum dolor nyob rau hauv occaecat commodo thiab voluptate minim reprehenderit mollit pariatur. Deserunt non Laborum enim thiab cillum eu deserunt excepteur thiab incidunt 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.
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-toggle="tab"
lossis data-toggle="pill"
ntawm lub ntsiab lus. Siv cov ntaub ntawv tus cwj pwm ntawm .nav-tabs
lossis .nav-pills
.
Ntawm JavaScript
Qhib tabbable tabs ntawm JavaScript (txhua tab yuav tsum tau qhib ib tus zuj zus):
Koj tuaj yeem qhib ib tus neeg tab hauv ntau txoj hauv kev:
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.
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 .
$().tab
Activates lub tab element thiab cov ntsiab lus ntim. Tab yuav tsum muaj ib data-target
lossis ib lub href
hom phiaj rau lub thawv ntim hauv DOM.
.tab('show')
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).
.tab('tso')
Ua kom puas lub ntsiab tab.
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. |
ua.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. |