Navbar
Fa'amaumauga ma fa'ata'ita'iga mo le fa'auluuluga fa'atonu mamana a Bootstrap, le navbar. E aofia ai le lagolago mo le fa'ailogaina, fa'atautaiga, ma isi mea, e aofia ai le lagolago mo la tatou fa'apalapala pa'u.
E faapefea ona galue
O mea nei e tatau ona e iloa ae e te leʻi amataina le navbar:
- Navbars e manaʻomia se afifiina mo vasega pa'u ma
.navbar
lanu lanu ..navbar-expand{-sm|-md|-lg|-xl|-xxl}
- Navbars ma a latou mea o loʻo i totonu o loʻo faʻafefe ona o le faaletonu. Suia le atigipusa e faʻatapulaʻa le lautele faʻalava i auala eseese.
- Fa'aoga a matou va'aiga ma fetu'utu'una'i vasega aoga mo le fa'atonutonuina o le va ma le fa'aogaina i totonu o navbars.
- Navbars e tali mai e ala i le le mafai, ae e faigofie ona e suia e sui ai lena mea. O amioga tali atu e fa'alagolago i la matou Collapse JavaScript plugin.
- Fa'amautinoa le fa'aogaina e ala i le fa'aogaina o se
<nav>
elemene po'o, pe a fa'aaogaina se elemene e sili atu le lautele e pei o le<div>
, fa'aopoopo serole="navigation"
i luga ole navbar uma e fa'ailoa manino ai o se fa'ailoga mata'ina mo tagata fa'aoga tekinolosi fesoasoani. - Fa'ailoa le mea o lo'o i ai nei e ala i le fa'aoga
aria-current="page"
mo le itulau o lo'o i ai nei po'oaria-current="true"
le mea o lo'o iai nei i se seti. - Fou i le v5.2.0: Navbars e mafai ona faʻauluina i CSS fesuiaiga o loʻo faʻaogaina i le
.navbar
vasega faavae..navbar-light
ua le toe fa'aaogaina ma.navbar-dark
ua toe tusia e fa'amalo ai suiga CSS nai lo le fa'aopoopoina o sitaili fa'aopoopo.
prefers-reduced-motion
aufaasālalau. Va'ai le vaega
fa'aitiitiga fa'aitiitiga oa matou pepa fa'aoga avanoa .
Mea e lagolagoina
Navbars e sau ma faʻapipiʻi i totonu o le lagolago mo ni nai vaega laiti. Filifili mai mea nei pe a manaʻomia:
.navbar-brand
mo lau kamupani, oloa, po'o le igoa ole poloketi..navbar-nav
mo se folauga maualuga ma mama (e aofia ai le lagolago mo pa'u i lalo)..navbar-toggler
mo le fa'aoga i la matou fa'apalapala pa'u ma isi fa'asologa aga fa'asolo .- Feso'ota'i ma fa'aoga avanoa mo so'o se fa'atonuga ma gaioiga.
.navbar-text
mo le fa'aopoopoina o laina fa'aogatotonu i luga o le sa'o o tusitusiga..collapse.navbar-collapse
mo le fa'avasegaina ma le nanaina o mea o lo'o i totonu o le navbar e ala i se va'aiga matua.- Fa'aopoopo i ai se filifiliga
.navbar-scroll
e seti aimax-height
ma fa'asolo le fa'alauteleina o mea navbar .
O se fa'ata'ita'iga lea o vaega laiti uma o lo'o aofia i totonu o se navbar e fa'atatau i le malamalama e otometi lava ona pa'u ile lg
(tele) malepe.
<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>
O lenei fa'ata'ita'iga e fa'aoga ai le talaaga ( bg-light
) ma le va'aiga ( me-auto
, mb-2
, mb-lg-0
, me-2
) vasega aoga.
Fa'ailoga
E .navbar-brand
mafai ona faʻaoga i le tele o elemene, ae sili ona aoga le taula, ona o nisi elemene e ono manaʻomia ai vasega aoga poʻo sitaili masani.
Tusitusi
Fa'aopoopo lau tusitusiga i totonu o se elemene ma le .navbar-brand
vasega.
<!-- 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>
Ata
E mafai ona e suia le tusitusiga i totonu o .navbar-brand
le <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>
Ata ma tusitusiga
E mafai fo'i ona e fa'aogaina nisi mea fa'aopoopo e fa'aopoopo ai se ata ma tusitusiga i le taimi e tasi. Matau le faaopoopoga o .d-inline-block
ma .align-text-top
luga o le <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
Navbar navigation links e fausia i luga oa tatou .nav
filifiliga ma a latou lava vasega faʻaleleia ma manaʻomia le faʻaogaina o vasega toggler mo le faʻaogaina talafeagai. O le a fa'atupula'ia fo'i le fa'atauta'iga i luga ole laiga e nofoia le tele o avanoa fa'ata'amilo e mafai ai ona fa'atutu lelei lau fa'aoga o le navbar.
Fa'aopoopo le .active
vasega .nav-link
e fa'ailoa ai le itulau o lo'o iai nei.
Faamolemole ia matau e tatau foi ona e faaopoopo le aria-current
uiga i le active .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 talu ai matou te faʻaogaina vasega mo a matou navs, e mafai ona e aloese mai le faʻaogaina o le lisi atoa pe a e fiafia i ai.
<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>
E mafai fo'i ona e fa'aogaina fa'alalo i lau navbar. E mana'omia e menus dropdown se elemene afifi mo le fa'atulagaina, ia mautinoa e fa'aaoga elemene eseese ma fa'aputu mo .nav-item
ma .nav-link
pei ona fa'aalia i lalo.
<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>
Fomu
Tu'u ni fa'atonuga ma vaega 'ese'ese i totonu ole navbar:
<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>
Elemene a tamaiti o le .navbar
fa'aoga fetuutuuna'i le fa'atulagaina ma o le a fa'aletonu i le justify-content: space-between
. Fa'aaogā mea fa'aoga felefele fa'aopoopo pe a mana'omia e fa'afetaui ai lenei amio.
<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>
E galue fo'i vaega fa'aoga. Afai o lau navbar o se pepa atoa, poʻo le tele o se fomu, e mafai ona e faʻaogaina le <form>
elemene e fai ma pusa ma faʻasaoina nisi 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>
O fa'amau eseese o lo'o lagolagoina o se vaega o nei fomu navbar, fo'i. Ose fa'amanatu sili foi lea e mafai ona fa'aoga mea fa'aoga fa'atutusa e fa'aoga ai elemene eseese.
<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>
Tusitusi
Navbars e mafai ona i ai ni vaega o tusitusiga ma le fesoasoani a .navbar-text
. O lenei vasega e fetu'una'i le fa'asolo i luga ma le avanoa fa'alava mo manoa o tusitusiga.
<nav class="navbar bg-light">
<div class="container-fluid">
<span class="navbar-text">
Navbar text with an inline element
</span>
</div>
</nav>
Faafefiloi ma fetaui ma isi vaega ma mea aoga pe a manaʻomia.
<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>
Fa'ailoga lanu
.navbar-light
ua le toe fa'aaogaina. CSS fesuia'iga e fa'aoga i
.navbar
, fa'aletonu i foliga "malamalama", ma e mafai ona fa'asolo i le
.navbar-dark
.
Navbar autu e sili atu ona faigofie nai lo se isi lava taimi faʻafetai i le tuʻufaʻatasia a Bootstrap o Sass ma CSS fesuiaiga. O le faaletonu o le matou "navbar malamalama" mo le faʻaaogaina i lanu malamalama, ae e mafai foi ona e talosaga .navbar-dark
mo lanu pogisa. Ona, faʻavasegaina ma .bg-*
mea faʻaoga.
<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>
Koneteina
E ui lava e le manaʻomia, e mafai ona e afifiina se navbar i totonu .container
e faʻatotonu i luga o se itulau-e ui o loʻo manaʻomia se atigipusa i totonu. Pe mafai ona e fa'aopoopoina se atigipusa i totonu o le .navbar
na'o totonugalemu o mea o lo'o i totonu o se fa'amaufa'ailoga pito i luga .
<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>
Fa'aoga so'o se koneteina tali mai e sui ai le lautele o mea o lo'o fa'aalia i lau navbar.
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-md">
<a class="navbar-brand" href="#">Navbar</a>
</div>
</nav>
Tulaga
Fa'aoga a matou tulaga fa'aoga e tu'u ai navbars i tulaga e le fa'amautu. Filifili mai le fa'amau i luga, fa'amau i lalo, fa'apipi'i i le pito i luga (ta'ai ma le itulau se'ia o'o i le pito i luga, ona nofo ai lea iina), po'o le pipii i lalo (ta'ai ma le itulau se'ia o'o i lalo, ona tumau ai lea iina).
Fa'aoga navbars fa'amaumau position: fixed
, o lona uiga e toso mai le tafe masani a le DOM ma e ono mana'omia le CSS masani (fa'ata'ita'iga, padding-top
i luga o le <body>
) e puipuia ai le sosolo ma isi elemene.
<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>
Tusitala
Fa'aopoopo .navbar-nav-scroll
i se .navbar-nav
(po'o se isi vaega o le navbar) ina ia mafai ai ona ta'avale i luga i luga o le mea e mafai ona fesuia'i i totonu o se navbar ua pa'u. E le mafai, o le taʻavale e kiki i totonu 75vh
(poʻo le 75% o le maualuga o le vaʻaia), ae e mafai ona e faʻaogaina i le CSS mea totino --bs-navbar-height
masani poʻo sitaili masani. I va'aiga lapopoa pe a fa'alautele le navbar, o le a fa'aalia mea e pei ona i ai i le navbar fa'aletonu.
Faamolemole ia matau o lenei amioga e sau faatasi ma se faaletonu o le overflow
-pe a setiina overflow-y: auto
(manaomia e ta'ai ai le anotusi iinei), overflow-x
e tutusa ma le auto
, lea o le a tipiina ai nisi mea faalava.
O se fa'ata'ita'iga navbar fa'aoga .navbar-nav-scroll
ma le style="--bs-scroll-height: 100px;"
, fa'atasi ai ma nisi fa'aoga fa'asili mo le avanoa sili ona lelei.
<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>
Amioga tali atu
E mafai e Navbars ona fa'aoga .navbar-toggler
, .navbar-collapse
, ma .navbar-expand{-sm|-md|-lg|-xl|-xxl}
vasega e iloa ai pe o a latou mea e pa'u i tua o se ki. Faʻatasi ma isi faʻaoga, e faigofie ona e filifilia le taimi e faʻaalia pe nana ai elemene faapitoa.
Mo navbars e le mafai ona pa'u, fa'aopoopo le .navbar-expand
vasega ile navbar. Mo navbars e pa'u i taimi uma, aua le fa'aopoopoina se .navbar-expand
vasega.
Toggler
Navbar togglers o lo'o fa'aoga agavale ona o le fa'aletonu, ae afai latou te mulimuli i se uso e pei o le .navbar-brand
, o le a otometi lava ona fa'aoga i le itu taumatau. O le toe fesuia'i o lau fa'ailoga o le a toe fa'afo'i ai le tu'uga o le koli. O lo'o i lalo ni fa'ata'ita'iga o sitaili fe'avea'i eseese.
E aunoa ma se .navbar-brand
fa'aalia i le pito la'ititi la'ititi:
<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>
Faatasi ai ma se igoa faʻailoga o loʻo faʻaalia i le agavale ma le toggle i le taumatau:
<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>
Faatasi ai ma se koli i le agavale ma le igoa fa'ailoga i le taumatau:
<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>
Anotusi fafo
O nisi taimi e te manaʻo e faʻaoga le faʻapipiʻi pa'ū e faʻaosoina ai se atigipusa elemene mo mea o loʻo nofo i fafo o le .navbar
. Ona o le matou plugin e galue i luga o le id
ma data-bs-target
fetaui, e faigofie lava ona fai!
<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>
A e faia lenei mea, matou te fautuaina le faʻaopoopoina o le JavaScript e faʻanofo ai le taulaiga faʻapolokalame i le koneteina pe a tatalaina. A leai, o le a faigata i tagata fa'aoga keyboard ma tagata fa'aogaina tekinolosi fesoasoani i le sailia o mea fou na fa'aalia - ae maise lava pe afai o le koneteina na tatalaina e sau i luma o le toggle i le fausaga o le pepa. Matou te fautuaina foi ia mautinoa o loʻo i ai i le toggles le aria-controls
uiga, faʻasino i le id
mea o loʻo i totonu. I le a'oa'oga, e mafai ai e tagata fa'aoga tekinolosi fesoasoani ona oso sa'o mai le toggle i le koneteina o lo'o pulea-ae o le lagolago mo lenei mea o lo'o fai si fa'aletonu.
Fa'alavalava
Su'i lau fa'alava fa'alautele ma pa'u i lalo i totonu o se atigi tapoleni fa'atasi ai ma le vaega o le tapoleni . Matou te fa'alauteleina uma sitaili fa'aletonu i fafo ma fa'aoga a matou .navbar-expand-*
vasega e fai ai se itu fa'atauva'a fa'amalosi ma fetu'una'i.
I le fa'ata'ita'iga o lo'o i lalo, e fa'atupu ai se fa'alava fa'alava e fa'ase'e i taimi uma i va'aiga uma, fa'ate'a .navbar-expand-*
atoa le vasega.
<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>
Ina ia fatuina se navbar offcanvas e faʻalautele i se faʻailoga masani i se nofoaga faʻapitoa e pei o lg
le , faʻaaoga .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>
A fa'aogaina le offcanvas i se fa'apolopolo pogisa, ia e nofouta e ono mana'omia le i ai o se ata pogisa i luga o le anotusi o fafo e 'alofia ai le le mafai ona faitau tusi. I le faʻataʻitaʻiga o loʻo i lalo, matou te faʻaopoopoina .navbar-dark
ma .bg-dark
le .navbar
, .text-bg-dark
i le .offcanvas
, .dropdown-menu-dark
i le .dropdown-menu
, ma .btn-close-white
le .btn-close
mo le faʻaogaina lelei ma se tapoleni pogisa.
<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
Fuafuaga
Fa'aopoopo i le v5.2.0I le avea ai o se vaega o le suiga o le CSS suiga a le Bootstrap, o loʻo faʻaogaina e navbars faʻaoga CSS faʻapitonuʻu i luga .navbar
mo le faʻaleleia o aganuʻu taimi moni. O tau mo le CSS fesuiaiga e faʻatulagaina e ala i le Sass, o lea o loʻo lagolagoina pea le Sass customization.
--#{$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};
O lo'o iai fo'i nisi suiga fa'aopoopo CSS i .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);
Fa'asinomaga e ala i le CSS fesuiaiga e mafai ona va'aia i luga o le .navbar-dark
vasega lea tatou te fa'amalo ai fa'atatauga fa'apitoa e aunoa ma le fa'aopoopoina o fa'alua CSS filifilia.
--#{$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 fesuiaiga
Su'ega mo navbars uma:
$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;
Su'ega mo le navbar pogisa :
$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 tali fa'alautele/fa'alalo vasega (fa'ata'ita'iga, .navbar-expand-lg
) e tu'ufa'atasia ma le $breakpoints
fa'afanua ma fa'atupuina e ala i se matasele i 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;
}
}
}
}
}
}