Nwoma ne nhwɛsoɔ ma Bootstrap ahoɔden, mmuaeɛ akwantuo ti, navbar. Nea ɛka ho ne mmoa a wɔde ma branding, navigation, ne nea ɛkeka ho, a mmoa a wɔde ma yɛn collapse plugin no ka ho.
Sɛnea ɛyɛ adwuma
Nea ɛsɛ sɛ wuhu ansa na woafi ase de navbar no ni:
Navbars ne emu nsɛm no yɛ nsu default. Fa nsukorade a wopɛ di dwuma de siw wɔn trɛw a ɛkɔ soro no ano hye.
Fa yɛn spacing ne flex utility classes no di dwuma ma hwɛ spacing ne alignment wɔ navbars mu.
Navbars no yɛ mmuae default so, nanso wubetumi asesa no ntɛm de asesa saa. Suban a ɛma mmuae gyina yɛn Collapse JavaScript plugin no so.
Navbars no wɔde sie default so bere a woretintim no. Hyɛ wɔn ma wontintim denam nea wode bɛka ho .d-printno so .navbar. Hwɛ ɔyɛkyerɛ utility adesuakuw no.
Hwɛ sɛ wobɛtumi anya bi denam <nav>element bi a wode bedi dwuma so anaasɛ, sɛ wode element a ɛyɛ generic kɛse te sɛ a redi dwuma a <div>, fa a ka role="navigation"navbar biara ho de kyerɛ pefee sɛ ɛyɛ ɔmantam a ɛyɛ agyiraehyɛde ma wɔn a wɔde mfiridwuma a ɛboa di dwuma no.
.collapse.navbar-collapsema navbar mu nsɛm a wɔde akuwakuw na wɔde sie denam ɔwofo breakpoint so.
Nhwɛsoɔ a ɛfa sub-components nyinaa a ɛka ho wɔ responsive light-themed navbar a ɛhwe ase ankasa wɔ lg(kɛseɛ) breakpoint no nie.
Saa nhwɛsoɔ yi de kɔla ( bg-light) ne ntamgyinafoɔ ( my-2, my-lg-0, mr-sm-0, my-sm-0) mfasoɔ adesua ahodoɔ di dwuma.
Adeban
Wobetumi de The .navbar-brandno adi dwuma wɔ element dodow no ara ho, nanso anchor yɛ adwuma yiye efisɛ element ahorow bi betumi ahwehwɛ utility classes anaa custom styles.
Ɛda adi sɛ mfonini ahorow a wode bɛka ho no .navbar-brandbɛhwehwɛ bere nyinaa sɛ wobɛyɛ custom styles anaa utilities na ama ne kɛse ayɛ yiye. Nhwɛso ahorow bi a yebetumi ayɛ ho ɔyɛkyerɛ ni.
Nav
Navbar navigation links si yɛn .navoptions so ne wɔn ankasa modifier class na ɛhwehwɛ sɛ wɔde toggler classes di dwuma ma mmuae a ɛfata styling. Navigation wɔ navbars mu nso bɛnyin akɔfa horizontal space pii sɛdeɛ ɛbɛyɛ yie na ama wo navbar mu nsɛm no akɔ so ayɛ pɛpɛɛpɛ.
Wobetumi de tebea horow a ɛyɛ adwuma—a .active—a ɛkyerɛ kratafa a ɛwɔ hɔ mprempren no adi dwuma tẽẽ wɔ .nav-links anaa wɔn awofo a wɔbɛn wɔn pɛɛ .nav-items so.
Na esiane sɛ yɛde classes di dwuma ma yɛn navs nti, wubetumi akwati list-based approach no koraa sɛ wopɛ a.
Wubetumi nso de dropdowns adi dwuma wɔ wo navbar nav no mu. Dropdown menus hwehwɛ wrapping element ma positioning, enti hwɛ hu sɛ wode elements a ɛtetew ne nested bedi dwuma ama .nav-itemne .nav-linksɛnea wɔakyerɛ wɔ ase ha no.
Nkyerɛwee ahorow
Fa form controls ne components ahorow gu navbar bi mu a .form-inline.
Ntɛm ara mmofra elements a .navbarwɔde di dwuma flex layout na ɛbɛ default akɔ justify-content: space-between. Fa flex utilities foforo di dwuma sɛnea ɛho hia na woasiesie saa suban yi.
Input akuw ahorow nso yɛ adwuma:
Wɔboa bɔton ahorow sɛ navbar nkrataa yi fã, nso. Eyi nso yɛ nkaebɔ kɛse sɛ wobetumi de vertical alignment utilities adi dwuma de ahyɛ element ahorow a ɛsono ne kɛse hyia.
Atwerɛ
Navbars betumi akura nsɛm nketenkete bi a ɛnam .navbar-text. Saa adesua yi sesa vertical alignment ne horizontal spacing ma nsɛm a wɔahyehyɛ no nhama.
Fa fra na fa nneɛma afoforo ne nneɛma a wɔde di dwuma no fra mu sɛnea ɛho hia.
Kɔla ahorow a wɔde yɛ nneɛma
Theming navbar no nyɛ mmerɛw da esiane theming adesua ahorow ne background-colorutilities a wɔaka abom nti. Paw bi .navbar-lightna wode bedi dwuma wɔ akyi kɔla a ɛyɛ hann, anaasɛ .navbar-darkakyi kɔla a ɛyɛ sum. Afei, fa .bg-*utilities yɛ wo ho sɛnea wopɛ.
Sɛ container no wɔ wo navbar no mu a, woyi ne horizontal padding no fi hɔ wɔ breakpoints a ɛba fam sen wo .navbar-expand{-sm|-md|-lg|-xl}class a woakyerɛ no. Wei hwɛ sɛ yɛrenyɛ doubling up wɔ padding a ɛho nhia wɔ lower viewports bere a wo navbar no abubu.
Nneɛma a wɔde bɛto hɔ
Fa yɛn gyinabea utilities no si navbars wɔ gyinabea a ɛnyɛ static. Paw fixed to the top, fixed to the bottom, anaa stickied to the top (fa kratafa no kyerɛw kosi sɛ ebedu soro, afei ɛtra hɔ). Fixed navbars de di dwuma position: fixed, a ɛkyerɛ sɛ wɔtwe wɔn fi DOM no nsu a ɛsen daa no mu na ebetumi ahwehwɛ CSS a wɔahyɛ da ayɛ (sɛ nhwɛso no, padding-topwɔ <body>) no so na asiw nneɛma afoforo a ɛbɛka abom no ano.
Navbars betumi de .navbar-toggler, .navbar-collapse, ne .navbar-expand{-sm|-md|-lg|-xl}adesua ahorow adi dwuma de asesa bere a wɔn nsɛm no ahwe ase wɔ bɔtn bi akyi no. Sɛ wode nneɛma afoforo ka ho a, ɛnyɛ den sɛ wobɛpaw bere a wobɛkyerɛ anaa wode nneɛma pɔtee bi besie.
Sɛ wopɛ navbars a ɛnhwe ase da a, fa .navbar-expandclass no ka ho wɔ navbar no so. Navbars a ɛhwe ase bere nyinaa no, mfa .navbar-expandadesua biara nka ho.
Toggler a wɔde yɛ nneɛma
Navbar togglers no yɛ benkum-aligned default, nanso sɛ wodi sibling element akyi te sɛ a .navbar-brand, wɔbɛfa wɔn ho akɔ nifa so koraa. Sɛ wodan wo markup no a, ɛbɛdan toggler no a wode besi hɔ no. Ase hɔ no yɛ nhwɛso ahorow a ɛfa toggle style ahorow ho.
Bere a .navbar-brandwɔankyerɛ biara wɔ breakpoint a ɛba fam koraa mu:
Bere a wɔakyerɛ brand din wɔ benkum so ne toggler wɔ nifa so:
Na toggler wɔ benkum so na brand din wɔ nifa so:
Nsɛm a ɛwɔ akyi
Ɛtɔ da bi a wopɛ sɛ wode collapse plugin no di dwuma de kanyan nsɛm a ahintaw wɔ kratafa no baabi foforo. Esiane sɛ yɛn plugin no yɛ adwuma wɔ idne data-targetmatching no so nti, ɛno yɛ mmerɛw sɛ wɔbɛyɛ!