Navbar
Akwụkwọ na ihe atụ maka isi igodo ụzọ Bootstrap na-anabata nke ọma, navbar. Gụnyere nkwado maka akara, igodo, na ndị ọzọ, gụnyere nkwado maka ngwa mgbakwunye ọdịda anyị.
Ka o si arụ ọrụ
Nke a bụ ihe ị kwesịrị ịma tupu ịmalite na navbar:
- Navbars chọrọ akwa mkpuchi
.navbar
maka klaasị na-anabata ndakpọ.navbar-expand{-sm|-md|-lg|-xl|-xxl}
na agba . - Navbars na ihe dị n'ime ha na-agbapụta na ndabara. Gbanwee akpa iji kpachie obosara ha n'ụzọ dị iche iche.
- Jiri ohere ohere anyị na flex uru klaasị maka ịchịkwa oghere na nhazi n'ime navbars.
- Navbars na-anabata ya na ndabara, mana ị nwere ike gbanwee ya ngwa ngwa ka ọ gbanwee nke ahụ. Omume nnabata dabere na ngwa mgbakwunye Javascript anyị dara.
- Gbaa mbọ hụ na ịnweta ya site na iji
<nav>
mmewere ma ọ bụ, ọ bụrụ na ị na-eji ihe ndị ọzọ dị ka a<div>
, tinye arole="navigation"
na navbar ọ bụla iji kọwaa ya nke ọma dị ka mpaghara ama ama maka ndị ọrụ teknụzụ enyemaka. - Gosi ihe dị ugbu a site na iji
aria-current="page"
maka ibe dị ugbu a ma ọ bụaria-current="true"
maka ihe dị ugbu a na setịpụ. - Ọhụrụ na v5.2.0: Navbars nwere ike nwee mgbanwe CSS nke etinyere na
.navbar
klaasị isi..navbar-light
a kagbuola ma.navbar-dark
degharịa ya ka ọ kagbuo mgbanwe CSS kama ịgbakwunye ụdị ndị ọzọ.
prefers-reduced-motion
ajụjụ mgbasa ozi. Hụ akụkụ
ngagharị ewelatala nke akwụkwọ nnweta anyị .
Ọdịnaya akwadoro
Navbars na-abịa na nkwado arụnyere n'ime ya maka ntakịrị obere akụkụ. Họrọ n'ime ihe ndị a dị ka achọrọ:
.navbar-brand
maka ụlọ ọrụ gị, ngwaahịa, ma ọ bụ aha oru ngo..navbar-nav
maka ịnya ụgbọ elu zuru oke na nke dị fechaa (gụnyere nkwado maka ọdịda ọdịda)..navbar-toggler
maka iji na ngwa mgbakwunye ọdịda anyị yana omume ngbanwe igodo ndị ọzọ .- Flex na spacing utilities maka ụdị ọ bụla njikwa na omume.
.navbar-text
maka ịgbakwunye eriri ederede kwụ n'etiti..collapse.navbar-collapse
maka ichikota na izobe ọdịnaya navbar site na ebe ezumike nne na nna.- Tinye nhọrọ
.navbar-scroll
ka ịtọmax-height
ma pịgharịa ọdịnaya navbar gbasaara .
Nke a bụ ọmụmaatụ nke akụkụ-akụkụ niile gụnyere na navbar ọkụ na-anabata nke na-ada ozugbo na ebe nkwụsị lg
(nnukwu).
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" 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><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
Ọmụmaatụ a na-eji klaasị ndabere ( bg-light
) na oghere ( me-auto
, mb-2
, mb-lg-0
) me-2
klaasị.
Ụdị
Enwere .navbar-brand
ike itinye ya na ọtụtụ ihe, mana arịlịka na-arụ ọrụ kacha mma, dịka ụfọdụ ihe nwere ike ịchọ klaasị bara uru ma ọ bụ ụdị omenala.
Ederede
Tinye ederede gị n'ime mmewere na .navbar-brand
klas.
<!-- As a link -->
<nav class="navbar bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
</div>
</nav>
<!-- As a heading -->
<nav class="navbar bg-light">
<div class="container-fluid">
<span class="navbar-brand mb-0 h1">Navbar</span>
</div>
</nav>
Onyonyo
.navbar-brand
Ị nwere ike dochie ederede n'ime <img>
.
<nav class="navbar bg-light">
<div class="container">
<a class="navbar-brand" href="#">
<img src="/docs/5.2/assets/brand/bootstrap-logo.svg" alt="Bootstrap" width="30" height="24">
</a>
</div>
</nav>
Foto na ederede
Ịnwekwara ike iji ụfọdụ akụrụngwa agbakwunyere tinye onyonyo na ederede n'otu oge. Rịba ama mgbakwunye .d-inline-block
na .align-text-top
na <img>
.
<nav class="navbar bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="/docs/5.2/assets/brand/bootstrap-logo.svg" alt="Logo" width="30" height="24" class="d-inline-block align-text-top">
Bootstrap
</a>
</div>
</nav>
Nav
Njikọ igodo Navbar na-eji klaasị mgbanwe nke ha na-ewuli na .nav
nhọrọ anyị ma chọọ ka e jiri klaasị toggler maka ịke na-anabata nke ọma. Ntugharị na navbars ga-etokwa iji nọrọ n'obere oghere dị ka o kwere mee iji dowe ọdịnaya navbar gị n'otu n'otu nke ọma.
Tinye .active
klas ahụ .nav-link
iji gosi ibe dị ugbu a.
Biko mara na ị ga-agbakwunyekwa aria-current
njirimara na arụ ọrụ .nav-link
.
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>
Ma n'ihi na anyị na-eji klaasị maka ụgbọ mmiri anyị, ị nwere ike zere usoro dabere na ndepụta kpamkpam ma ọ bụrụ na-amasị gị.
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-link active" aria-current="page" href="#">Home</a>
<a class="nav-link" href="#">Features</a>
<a class="nav-link" href="#">Pricing</a>
<a class="nav-link disabled">Disabled</a>
</div>
</div>
</div>
</nav>
Ị nwekwara ike iji dropdowns na navbar gị. Nchịkọta nhọrọ mwụda chọrọ ihe mkpuchi maka idowe, yabụ jide n'aka na ị na-eji ihe dị iche iche na akwụghị ụgwọ maka .nav-item
yana .nav-link
dị ka egosiri n'okpuru.
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown link
</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>
</ul>
</li>
</ul>
</div>
</div>
</nav>
Ụdị
Debe njikwa ụdị dị iche iche na ihe mejupụtara n'ime ụgbọ mmiri:
<nav class="navbar bg-light">
<div class="container-fluid">
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</nav>
Ngwa ngwa ihe ụmụaka na- .navbar
eji okirikiri nhọrọ ukwuu ga-adabara na justify-content: space-between
. Jiri ihe ndị ọzọ na-agbanwe agbanwe dị ka achọrọ iji dozie omume a.
<nav class="navbar bg-light">
<div class="container-fluid">
<a class="navbar-brand">Navbar</a>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</nav>
Otu ntinye na-arụkwa ọrụ. Ọ bụrụ na navbar gị bụ ụdị dum, ma ọ bụ na-abụkarị ụdị, ị nwere ike iji <form>
mmewere dị ka akpa wee chekwaa ụfọdụ HTML.
<nav class="navbar bg-light">
<form class="container-fluid">
<div class="input-group">
<span class="input-group-text" id="basic-addon1">@</span>
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
</div>
</form>
</nav>
A na-akwado bọtịnụ dị iche iche dịka akụkụ nke ụdị navbar ndị a, kwa. Nke a bụkwa ihe ncheta dị ukwuu na enwere ike iji akụrụngwa nhazi kwụ ọtọ iji kwado ihe nha dị iche iche.
<nav class="navbar bg-light">
<form class="container-fluid justify-content-start">
<button class="btn btn-outline-success me-2" type="button">Main button</button>
<button class="btn btn-sm btn-outline-secondary" type="button">Smaller button</button>
</form>
</nav>
Ederede
Navbars nwere ike ịnwe ntakịrị ederede site na enyemaka nke .navbar-text
. Klas a na-edozi nhazi kwụ ọtọ na oghere kwụ ọtọ maka eriri ederede.
<nav class="navbar bg-light">
<div class="container-fluid">
<span class="navbar-text">
Navbar text with an inline element
</span>
</div>
</nav>
Gwakọta ma jikọta ya na ihe ndị ọzọ na akụrụngwa dị ka achọrọ.
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar w/ text</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
</ul>
<span class="navbar-text">
Navbar text with an inline element
</span>
</div>
</div>
</nav>
Atụmatụ agba
.navbar-light
emebiela ya. A na-etinye mgbanwe CSS na
.navbar
, na-adaba na ọdịdị "ìhè", enwere ike iji
.navbar-dark
.
Gburugburu Navbar dị mfe karịa mgbe ọ bụla n'ihi nchikota Bootstrap nke mgbanwe Sass na CSS. Ihe ndabara bụ “navbar ọkụ” anyị maka iji ya na agba okirikiri ọkụ, mana ị nwekwara ike itinye .navbar-dark
maka agba okirikiri gbara ọchịchịrị. Mgbe ahụ, hazie ya na .bg-*
utilities.
<nav class="navbar navbar-dark bg-dark">
<!-- Navbar content -->
</nav>
<nav class="navbar navbar-dark bg-primary">
<!-- Navbar content -->
</nav>
<nav class="navbar" style="background-color: #e3f2fd;">
<!-- Navbar content -->
</nav>
Akpa
Ọ bụ ezie na achọghị ya, ị nwere ike kechie navbar n'ime .container
ka etiti ya na ibe-n'agbanyeghị na rịba ama na akpa dị n'ime ka achọrọ. Ma ọ bụ ị nwere ike itinye akpa n'ime ka .navbar
ọ bụrụ naanị n'etiti ọdịnaya nke navbar dị elu ma ọ bụ kwụ ọtọ .
<div class="container">
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
</div>
</nav>
</div>
Jiri igbe ọ bụla na-anabata iji gbanwee etu esi ewepụta ọdịnaya dị na navbar gị.
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-md">
<a class="navbar-brand" href="#">Navbar</a>
</div>
</nav>
Ndokwa
Jiri akụrụngwa ọnọdụ anyị tinye navbars n'ọkwa na-abụghị static. Họrọ site na edoziri ruo n'elu, nke edobere na ala, rapara n'elu (akwụkwọ mpịakọta na ibe ahụ ruo mgbe ọ ruru n'elu, wee nọrọ n'ebe ahụ), ma ọ bụ rapagidesie ike na ala (akwụkwọ mpịakọta na ibe ahụ ruo mgbe ọ ruru ala, wee nọrọ na ya. Ebe ahụ).
Navbars edobere anya na-eji position: fixed
, nke pụtara na a dọpụrụ ha na DOM nkịtị ma nwee ike chọọ CSS omenala (dịka ọmụmaatụ, padding-top
na <body>
) iji gbochie iji ihe ndị ọzọ kpuchie ya.
<nav class="navbar bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Default</a>
</div>
</nav>
<nav class="navbar fixed-top bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Fixed top</a>
</div>
</nav>
<nav class="navbar fixed-bottom bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Fixed bottom</a>
</div>
</nav>
<nav class="navbar sticky-top bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Sticky top</a>
</div>
</nav>
<nav class="navbar sticky-bottom bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Sticky bottom</a>
</div>
</nav>
Na-atụgharị
Tinye .navbar-nav-scroll
na .navbar-nav
(ma ọ bụ akụkụ nke navbar ọzọ) iji mee ka mpịachi kwụ ọtọ n'ime ọdịnaya nwere ike ịgbanwegharị nke navbar dara ada. Site na ndabara, ịpịgharị na-abanye na 75vh
(ma ọ bụ 75% nke ịdị elu nlele), mana ị nwere ike iji akụrụngwa omenala CSS --bs-navbar-height
ma ọ bụ ụdị omenala mebie nke ahụ. N'ebe nlele buru ibu mgbe a na-agbasawanye navbar, ọdịnaya ga-apụta dịka ọ na-eme na navbar ndabara.
Biko mara na omume a na-abịa na ihe ndọghachi azụ nke overflow
—mgbe ịtọlite overflow-y: auto
(chọrọ ka ịpịgharịa ọdịnaya ebe a), overflow-x
bụ ihe nhata nke auto
, nke ga-egbutu ụfọdụ ọdịnaya kwụ ọtọ.
Nke a bụ ihe atụ navbar na-eji .navbar-nav-scroll
ya na style="--bs-scroll-height: 100px;"
, yana ụfọdụ ngwa mgbakwunye oke maka oghere kacha mma.
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar scroll</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarScroll" aria-controls="navbarScroll" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarScroll">
<ul class="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll" style="--bs-scroll-height: 100px;">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Link
</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><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link disabled">Link</a>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
Àgwà na-anabata
Navbars nwere ike iji .navbar-toggler
, .navbar-collapse
, na .navbar-expand{-sm|-md|-lg|-xl|-xxl}
klaasị chọpụta mgbe ọdịnaya ha daa n'azụ bọtịnụ. Na mgbakwunye na akụrụngwa ndị ọzọ, ị nwere ike họrọ ngwa ngwa mgbe ị ga-egosi ma ọ bụ zoo ụfọdụ ihe.
Maka ụgbọ mmiri ndị na-adịghị ada ada, tinye .navbar-expand
klas na navbar. Maka ụgbọ mmiri na-ada mgbe niile, etinyela .navbar-expand
klaasị ọ bụla.
Toggler
Ndị na-atụgharị Navbar na-adakọ aka ekpe site na ndabara, mana ọ bụrụ na ha soro mmemme nwanne dị ka a .navbar-brand
, a ga-ahazi ha ozugbo n'aka nri aka nri. Ịtụgharị akara gị ga-atụgharị ntinye nke toggler. N'okpuru bụ ọmụmaatụ ụdị ngbanwe dị iche iche.
Enweghị .navbar-brand
egosiri na ebe nkwụsị kacha nta:
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<a class="navbar-brand" href="#">Hidden brand</a>
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</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>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
Site na aha ika egosiri n'aka ekpe yana toggler n'aka nri:
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</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>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
Ya na toggler n'aka ekpe yana akara aha n'aka nri:
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>
<div class="collapse navbar-collapse" id="navbarTogglerDemo03">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</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>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
Ọdịnaya nke mpụga
Mgbe ụfọdụ, ịchọrọ iji ngwa mgbakwunye ọdịda iji kpalite mmewere akpa maka ọdịnaya nke na-anọdụ ala na mpụga .navbar
. N'ihi na ngwa mgbakwunye anyị na-arụ ọrụ id
na data-bs-target
matching, nke ahụ dị mfe ime!
<div class="collapse" id="navbarToggleExternalContent">
<div class="bg-dark p-4">
<h5 class="text-white h4">Collapsed content</h5>
<span class="text-muted">Toggleable via the navbar brand.</span>
</div>
</div>
<nav class="navbar navbar-dark bg-dark">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
Mgbe ị na-eme nke a, anyị na-akwado ịgụnye Javascript agbakwunyere iji bugharịa elekwasị anya na mmemme na akpa mgbe emepere ya. Ma ọ bụghị ya, ndị ọrụ ahụigodo na ndị na-eji teknụzụ enyemaka ga-esiri ike ịchọta ọdịnaya ekpughere ọhụrụ - ọkachasị ma ọ bụrụ na akpa e meghere na-abịa n'ihu onye na-emegharị ihe na nhazi akwụkwọ ahụ. Anyị na-akwadokwa ijide n'aka na toggler nwere aria-controls
njirimara ahụ, na-atụ aka na id
akpa ọdịnaya. Na tiori, nke a na-enye ohere ka ndị ọrụ nka na-enyere aka si na toggler wụpụ ozugbo gaa na akpa ọ na-achịkwa-mana nkwado maka nke a adịchaghị mma ugbu a.
Offcanvas
Tụgharịa navbar gị na-agbasawanye ma na-akụda ka ọ bụrụ drawer offcanvas nwere akụrụngwa apụ apụ . Anyị na-agbatị ma ụdị ndabara nke offcanvas ma jiri .navbar-expand-*
klaasị anyị mepụta akụkụ igodo ụzọ na-agbanwe agbanwe na-agbanwe agbanwe.
N'ihe atụ dị n'okpuru, iji mepụta oghere navbar na-apụ apụ nke na-adaba mgbe niile, hapụ .navbar-expand-*
klaasị ahụ kpamkpam.
<nav class="navbar bg-light fixed-top">
<div class="container-fluid">
<a class="navbar-brand" href="#">Offcanvas navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbar" aria-controls="offcanvasNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasNavbarLabel">Offcanvas</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" 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>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</div>
</nav>
Ka imepụta ihe navbar offcanvas nke na-agbasa ka ọ bụrụ navbar nkịtị n'otu ebe nkwụsịtụ dị ka lg
, jiri .navbar-expand-lg
.
<nav class="navbar navbar-expand-lg bg-light fixed-top">
<a class="navbar-brand" href="#">Offcanvas navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#navbarOffcanvasLg" aria-controls="navbarOffcanvasLg">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end" tabindex="-1" id="navbarOffcanvasLg" aria-labelledby="navbarOffcanvasLgLabel">
...
</div>
</nav>
Mgbe ị na-eji offcanvas n'ime oghere navbar gbara ọchịchịrị, mara na ọ ga-adị mkpa ka ị nwee ndabere gbara ọchịchịrị na ọdịnaya apụ apụ ka ọ bụrụ nke a na-edeghị ede. N'ihe atụ dị n'okpuru, anyị na-agbakwunye .navbar-dark
na .bg-dark
na .navbar
, .text-bg-dark
na .offcanvas
, .dropdown-menu-dark
na .dropdown-menu
, na .btn-close-white
maka .btn-close
nhazi nke ọma na akwa mkpuchi gbara ọchịchịrị.
<nav class="navbar navbar-dark bg-dark fixed-top">
<div class="container-fluid">
<a class="navbar-brand" href="#">Offcanvas dark navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end text-bg-dark" tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasDarkNavbarLabel">Dark offcanvas</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu dropdown-menu-dark">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-success" type="submit">Search</button>
</form>
</div>
</div>
</div>
</nav>
CSS
Mgbanwe
Agbakwunyere na v5.2.0Dịka akụkụ nke mgbanwe mgbanwe CSS nke Bootstrap, ndị navbar na-ejizi mgbanwe CSS mpaghara .navbar
maka imeziwanye ezigbo oge. A na-edozi ụkpụrụ maka mgbanwe CSS site na Sass, yabụ ka na-akwado nhazi Sass, kwa.
--#{$prefix}navbar-padding-x: #{if($navbar-padding-x == null, 0, $navbar-padding-x)};
--#{$prefix}navbar-padding-y: #{$navbar-padding-y};
--#{$prefix}navbar-color: #{$navbar-light-color};
--#{$prefix}navbar-hover-color: #{$navbar-light-hover-color};
--#{$prefix}navbar-disabled-color: #{$navbar-light-disabled-color};
--#{$prefix}navbar-active-color: #{$navbar-light-active-color};
--#{$prefix}navbar-brand-padding-y: #{$navbar-brand-padding-y};
--#{$prefix}navbar-brand-margin-end: #{$navbar-brand-margin-end};
--#{$prefix}navbar-brand-font-size: #{$navbar-brand-font-size};
--#{$prefix}navbar-brand-color: #{$navbar-light-brand-color};
--#{$prefix}navbar-brand-hover-color: #{$navbar-light-brand-hover-color};
--#{$prefix}navbar-nav-link-padding-x: #{$navbar-nav-link-padding-x};
--#{$prefix}navbar-toggler-padding-y: #{$navbar-toggler-padding-y};
--#{$prefix}navbar-toggler-padding-x: #{$navbar-toggler-padding-x};
--#{$prefix}navbar-toggler-font-size: #{$navbar-toggler-font-size};
--#{$prefix}navbar-toggler-icon-bg: #{escape-svg($navbar-light-toggler-icon-bg)};
--#{$prefix}navbar-toggler-border-color: #{$navbar-light-toggler-border-color};
--#{$prefix}navbar-toggler-border-radius: #{$navbar-toggler-border-radius};
--#{$prefix}navbar-toggler-focus-width: #{$navbar-toggler-focus-width};
--#{$prefix}navbar-toggler-transition: #{$navbar-toggler-transition};
Ụfọdụ mgbanwe CSS agbakwunyere dịkwa na .navbar-nav
:
--#{$prefix}nav-link-padding-x: 0;
--#{$prefix}nav-link-padding-y: #{$nav-link-padding-y};
@include rfs($nav-link-font-size, --#{$prefix}nav-link-font-size);
--#{$prefix}nav-link-font-weight: #{$nav-link-font-weight};
--#{$prefix}nav-link-color: var(--#{$prefix}navbar-color);
--#{$prefix}nav-link-hover-color: var(--#{$prefix}navbar-hover-color);
--#{$prefix}nav-link-disabled-color: var(--#{$prefix}navbar-disabled-color);
Enwere ike ịhụ nhazi site na mgbanwe CSS na .navbar-dark
klaasị ebe anyị na-ewepụ ụkpụrụ akọwapụtara na-agbakwunyeghị ndị na-ahọrọ CSS oyiri.
--#{$prefix}navbar-color: #{$navbar-dark-color};
--#{$prefix}navbar-hover-color: #{$navbar-dark-hover-color};
--#{$prefix}navbar-disabled-color: #{$navbar-dark-disabled-color};
--#{$prefix}navbar-active-color: #{$navbar-dark-active-color};
--#{$prefix}navbar-brand-color: #{$navbar-dark-brand-color};
--#{$prefix}navbar-brand-hover-color: #{$navbar-dark-brand-hover-color};
--#{$prefix}navbar-toggler-border-color: #{$navbar-dark-toggler-border-color};
--#{$prefix}navbar-toggler-icon-bg: #{escape-svg($navbar-dark-toggler-icon-bg)};
Sass variables
Ọdịiche maka ụgbọ mmiri niile:
$navbar-padding-y: $spacer * .5;
$navbar-padding-x: null;
$navbar-nav-link-padding-x: .5rem;
$navbar-brand-font-size: $font-size-lg;
// Compute the navbar-brand padding-y so the navbar-brand will have the same height as navbar-text and nav-link
$nav-link-height: $font-size-base * $line-height-base + $nav-link-padding-y * 2;
$navbar-brand-height: $navbar-brand-font-size * $line-height-base;
$navbar-brand-padding-y: ($nav-link-height - $navbar-brand-height) * .5;
$navbar-brand-margin-end: 1rem;
$navbar-toggler-padding-y: .25rem;
$navbar-toggler-padding-x: .75rem;
$navbar-toggler-font-size: $font-size-lg;
$navbar-toggler-border-radius: $btn-border-radius;
$navbar-toggler-focus-width: $btn-focus-width;
$navbar-toggler-transition: box-shadow .15s ease-in-out;
$navbar-light-color: rgba($black, .55);
$navbar-light-hover-color: rgba($black, .7);
$navbar-light-active-color: rgba($black, .9);
$navbar-light-disabled-color: rgba($black, .3);
$navbar-light-toggler-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-light-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");
$navbar-light-toggler-border-color: rgba($black, .1);
$navbar-light-brand-color: $navbar-light-active-color;
$navbar-light-brand-hover-color: $navbar-light-active-color;
Ọdịiche maka navbar gbara ọchịchịrị :
$navbar-dark-color: rgba($white, .55);
$navbar-dark-hover-color: rgba($white, .75);
$navbar-dark-active-color: $white;
$navbar-dark-disabled-color: rgba($white, .25);
$navbar-dark-toggler-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-dark-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");
$navbar-dark-toggler-border-color: rgba($white, .1);
$navbar-dark-brand-color: $navbar-dark-active-color;
$navbar-dark-brand-hover-color: $navbar-dark-active-color;
Sass loop
Navbar na-anabata klaasị gbasaa/dabie (dịka ọmụmaatụ .navbar-expand-lg
) na $breakpoints
maapụ wee mepụta ya site na akaghị scss/_navbar.scss
.
// Generate series of `.navbar-expand-*` responsive classes for configuring
// where your navbar collapses.
.navbar-expand {
@each $breakpoint in map-keys($grid-breakpoints) {
$next: breakpoint-next($breakpoint, $grid-breakpoints);
$infix: breakpoint-infix($next, $grid-breakpoints);
// stylelint-disable-next-line scss/selector-no-union-class-name
&#{$infix} {
@include media-breakpoint-up($next) {
flex-wrap: nowrap;
justify-content: flex-start;
.navbar-nav {
flex-direction: row;
.dropdown-menu {
position: absolute;
}
.nav-link {
padding-right: var(--#{$prefix}navbar-nav-link-padding-x);
padding-left: var(--#{$prefix}navbar-nav-link-padding-x);
}
}
.navbar-nav-scroll {
overflow: visible;
}
.navbar-collapse {
display: flex !important; // stylelint-disable-line declaration-no-important
flex-basis: auto;
}
.navbar-toggler {
display: none;
}
.offcanvas {
// stylelint-disable declaration-no-important
position: static;
z-index: auto;
flex-grow: 1;
width: auto !important;
height: auto !important;
visibility: visible !important;
background-color: transparent !important;
border: 0 !important;
transform: none !important;
@include box-shadow(none);
@include transition(none);
// stylelint-enable declaration-no-important
.offcanvas-header {
display: none;
}
.offcanvas-body {
display: flex;
flex-grow: 0;
padding: 0;
overflow-y: visible;
}
}
}
}
}
}