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, pa'u fa'apipi'i, ma isi mea.
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}
- Navbars ma a latou mea o loʻo i totonu o loʻo faʻafefe ona o le faaletonu. Fa'aoga koneteina e filifili ai e fa'atapula'a le lautele fa'alava.
- 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.
- Navbars e natia e ala i le faaletonu pe a lolomi. Faamalosia e lolomi e ala i le faaopoopo
.d-print
i le.navbar
. Va'ai le vasega fa'aaliga aoga. - 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.
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 ..form-inline
mo so'o se fomu 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.
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 navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
O lenei fa'ata'ita'iga e fa'aaoga ai le lanu ( bg-light
) ma le va ( ,,, ) vasega aoga .my-2
my-lg-0
mr-sm-0
my-sm-0
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.
<!-- As a link -->
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
</nav>
<!-- As a heading -->
<nav class="navbar navbar-light bg-light">
<span class="navbar-brand mb-0 h1">Navbar</span>
</nav>
O le fa'aopoopoina o ata i le ata e .navbar-brand
ono mana'omia ai sitaili fa'aaganu'u po'o mea fa'aoga i le lapopoa sa'o. O nisi nei o faʻataʻitaʻiga e faʻaalia.
<!-- Just an image -->
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand" href="#">
<img src="/docs/4.6/assets/brand/bootstrap-solid.svg" width="30" height="30" alt="">
</a>
</nav>
<!-- Image and text -->
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand" href="#">
<img src="/docs/4.6/assets/brand/bootstrap-solid.svg" width="30" height="30" class="d-inline-block align-top" alt="">
Bootstrap
</a>
</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.
Active states-with .active
-e faʻaalia ai le itulau o loʻo iai nei e mafai ona faʻaoga saʻo i .nav-link
s poʻo latou matua matua .nav-item
.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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 active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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>
</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 navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-link" href="#">Features</a>
<a class="nav-link" href="#">Pricing</a>
<a class="nav-link disabled">Disabled</a>
</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 navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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 active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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-toggle="dropdown" aria-expanded="false">
Dropdown link
</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>
</li>
</ul>
</div>
</nav>
Fomu
Tu'u ni fa'atonuga eseese ma vaega i totonu o se navbar ma .form-inline
.
<nav class="navbar navbar-light bg-light">
<form class="form-inline">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</nav>
Elemene a tamaiti o le .navbar
fa'aoga fetuutuunai 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 navbar-light bg-light">
<a class="navbar-brand">Navbar</a>
<form class="form-inline">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</nav>
E galue fo'i vaega fa'aoga:
<nav class="navbar navbar-light bg-light">
<form class="form-inline">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">@</span>
</div>
<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 navbar-light bg-light">
<form class="form-inline">
<button class="btn btn-outline-success" 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 navbar-light bg-light">
<span class="navbar-text">
Navbar text with an inline element
</span>
</nav>
Faafefiloi ma fetaui ma isi vaega ma mea aoga pe a manaʻomia.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar w/ text</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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>
</nav>
Fa'ailoga lanu
O le faʻaogaina o le navbar e leʻi faigofie lava faʻafetai i le tuʻufaʻatasia o vasega autu ma background-color
mea aoga. Filifili mai .navbar-light
mo le fa'aoga i lanu malamalama i tua, pe .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 navbar-light" 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. 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 navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
</nav>
</div>
A o'o le koneteina i totonu o lau navbar, e 'ave'esea lona fa'alava fa'alava ile va'a maualalo ifo nai lo lau .navbar-expand{-sm|-md|-lg|-xl}
vasega fa'apitoa. Ole mea lea e fa'amautinoa ai tatou te le fa'aluaina le fa'aofuofu fa'aletonu ile va'aiga pito i lalo pe a pa'u lau navbar.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<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 le pito i luga, fa'amau i lalo, po'o le pipii i le pito i luga (ta'ai ma le itulau se'ia o'o i le pito i luga, ona nofo 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.
Ia maitauina foi o le .sticky-top
fa'aoga position: sticky
, lea e le'o lagolagoina atoatoa i so'o se su'esu'ega .
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand" href="#">Default</a>
</nav>
<nav class="navbar fixed-top navbar-light bg-light">
<a class="navbar-brand" href="#">Fixed top</a>
</nav>
<nav class="navbar fixed-bottom navbar-light bg-light">
<a class="navbar-brand" href="#">Fixed bottom</a>
</nav>
<nav class="navbar sticky-top navbar-light bg-light">
<a class="navbar-brand" href="#">Sticky top</a>
</nav>
Tusitala
Fa'aopoopo .navbar-nav-scroll
i se .navbar-collapse
(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. Ona o le faaletonu, o le ta'avale e oso i totonu 75vh
(po'o le 75% o le maualuga o le va'aiga), ae e mafai ona e fa'aogaina i totonu o laina 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="max-height: 100px;"
, fa'atasi ai ma nisi fa'aoga fa'asili mo le avanoa sili ona lelei.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar scroll</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto my-2 my-lg-0 navbar-nav-scroll" style="max-height: 100px;">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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-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">
<input class="form-control mr-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</nav>
Amioga tali atu
E mafai e Navbars ona fa'aoga .navbar-toggler
, .navbar-collapse
, ma .navbar-expand{-sm|-md|-lg|-xl}
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 navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</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 navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
Faatasi ai ma se koli i le agavale ma le igoa fa'ailoga i le taumatau:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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 mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</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-target
fetaui, e faigofie lava ona fai!
<div class="fixed-top">
<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">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
</div>
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.