Navbar
Ditokomane le mehlala ya hlogo ya go sepelasepela ye maatla, ye e arabelago ya Bootstrap, navbar. E akaretša thekgo ya go swaya, go sepelasepela, le tše dingwe, go akaretšwa thekgo ya plugin ya rena ya go phuhlama.
Kamoo e šomago ka gona
Se o swanetšego go se tseba pele o thoma ka navbar ke se:
- Navbars hloka e phuthela
.navbar
le.navbar-expand{-sm|-md|-lg|-xl|-xxl}
bakeng sa arabela phuhlama le mebala sekema dihlopha. - Di-navbar le dikagare tša tšona di a seela ka go ikemela. Fetoša setshelo go lekanyetša bophara bja tšona bjo bo rapaletšego ka ditsela tše di fapanego.
- Šomiša diklase tša rena tša sekgoba le tša go koba tša mohola bakeng sa go laola sekgoba le go logaganya ka gare ga di-navbar.
- Di-navbar di arabela ka go ikemela, eupša o ka di fetoša gabonolo go fetoša seo. Boitshwaro bja go arabela bo ithekgile ka plugin ya rena ya Collapse JavaScript.
- Netefatša phihlelelo ka go šomiša
<nav>
elemente goba, ge o šomiša elemente ya kakaretšo kudu go swana le a<div>
, oketša arole="navigation"
go navbar ye nngwe le ye nngwe go e hlaola ka go lebanya bjalo ka selete sa leswao la naga go badiriši ba theknolotši ya go thuša. - Bontšha selo sa bjale ka go šomiša
aria-current="page"
bakeng sa letlakala la bjale gobaaria-current="true"
bakeng sa selo sa bjale ka seteng. - New ka v5.2.0: Navbars ka themed le CSS diphetogo tseo ba scoped ho
.navbar
sehlopha sa motheo..navbar-light
e tlošitšwe tirišong gomme.navbar-dark
e ngwadilwe gape go tloša diphetogo tša CSS go e na le go oketša mekgwa ya tlaleletšo.
prefers-reduced-motion
potšišo ya methopo ya ditaba. Bona
karolo ya tšhišinyego ye e fokoditšwego ya ditokomane tša rena tša phihlelelo .
Diteng tše di thekgwago
Di-navbar di tla le thekgo yeo e agetšwego ka gare bakeng sa dikarolo tše sego kae tše dinyenyane. Kgetha go tše di latelago ge go nyakega:
.navbar-brand
bakeng sa khamphani ya gago, setšweletšwa, goba leina la projeke..navbar-nav
bakeng sa go sepelasepela ga bophagamo bjo bo tletšego le bjo bo bobebe (go akaretša le thekgo ya dilo tšeo di theogago)..navbar-toggler
bakeng sa go dirišwa le plugin ya rena ya go phuhlama le maitshwaro a mangwe a go fetoša go sepelasepela .- Flex le spacing utilities bakeng sa leha e le efe foromo taolo le liketso.
.navbar-text
bakeng sa go oketša dithapo tša sengwalwa tšeo di tsepamego thwii..collapse.navbar-collapse
bakeng sa go hlopha le go uta dikagare tša navbar ka ntlha ya go kgaotša ya motswadi.- Oketša kgetho
.navbar-scroll
go beakanyamax-height
le go sepelasepela diteng tša navbar ye e katološitšwego .
Mona ke mohlala wa dikarolo ka moka tše nnyane tšeo di akareditšwego ka go navbar ya go arabela ya sehlogo sa seetša yeo e phuhlamago ka go iketla ntlheng ya go lg
kgaotša (ye kgolo).
<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>
Mohlala wo o šomiša diklase tša mohola tša bokamorago ( bg-light
) le sekgoba ( me-auto
, mb-2
, mb-lg-0
, ).me-2
Leswao
The .navbar-brand
e ka dirišwa go bontši bja dielemente, eupša ankora e šoma gabotse, ka ge dielemente tše dingwe di ka nyaka diklase tša mohola goba mekgwa ya tlwaelo.
Sengwalwa
Oketša sengwalwa sa gago ka gare ga elemente ka .navbar-brand
klase.
<!-- 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>
Seswantšho
O ka tšeela sengwalwa legato ka gare .navbar-brand
ga <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>
Seswantšho le sengwalwa
O ka dira gape tšhomišo ya didirišwa tše dingwe tša tlaleletšo go oketša seswantšho le sengwalwa ka nako e tee. Hlokomela tlaleletšo ya .d-inline-block
le .align-text-top
godimo ga <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
Dikgokagano tša go sepelasepela tša Navbar di aga godimo ga .nav
dikgetho tša rena ka sehlopha sa bona sa sefetoši gomme di nyaka tšhomišo ya diklase tša toggler bakeng sa setaele sa go arabela gabotse. Go sepelasepela ka go di-navbar le gona go tla gola go tšea sekgoba se segolo sa go rapalala ka mo go kgonegago go boloka dikagare tša gago tša navbar di logagane ka polokego.
Oketša .active
klase godimo .nav-link
go laetša letlakala la bjale.
Hle ela hloko gore o swanetše go oketša gape aria-current
seka go 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>
Gomme ka ge re šomiša diklase bakeng sa di-nav tša rena, o ka efoga mokgwa wo o theilwego lenaneong ka mo go feletšego ge e ba o rata.
<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>
O ka šomiša gape le dithepo tša go theoga ka go navbar ya gago. Dimenu tša go theoga di nyaka elemente ya go phuthela bakeng sa go beakanya, ka fao kgonthiša gore o šomiša dielemente tše di aroganego le tše di tsentšwego ka gare bakeng sa .nav-item
le .nav-link
bjalo ka ge go bontšhitšwe ka mo tlase.
<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>
Diforomo
Bea ditaolo tša foromo tše di fapafapanego le dikarolo ka gare ga 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>
Dielemente tša ngwana tša ka pela tša .navbar
tšhomišo di flex peakanyo gomme di tla default go justify-content: space-between
. Diriša didirišwa tša tlaleletšo tša go koba ge go nyakega go beakanya boitshwaro bjo.
<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>
Dihlopha tša tsenyo di a šoma, le tšona. Ge e le gore navbar ya gago ke foromo ka moka, goba bontši bja foromo, o ka šomiša <form>
elemente bjalo ka setshelo gomme wa boloka HTML ye nngwe.
<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>
Dikonope tše di fapafapanego di thekgwa bjalo ka karolo ya diforomo tše tša navbar, le tšona. Ye gape ke kgopotšo ye kgolo ya gore didirišwa tša go logaganya thwii di ka šomišwa go logaganya dielemente tša bogolo bjo bo fapanego.
<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>
Sengwalwa
Di-navbar di ka ba le diripana tša sengwalwa ka thušo ya .navbar-text
. Sehlopha se se beakanya go logaganya go ema le sekgoba sa go rapalala sa dithapo tša sengwalwa.
<nav class="navbar bg-light">
<div class="container-fluid">
<span class="navbar-text">
Navbar text with an inline element
</span>
</div>
</nav>
Kopanya le go nyalelanya le dikarolo tše dingwe le didirišwa ge go nyakega.
<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>
Dikema tša mebala
.navbar-light
e tlogetšwe. Diphetogo tša CSS di dirišwa go
.navbar
, di sa fetoge go ponagalo ya “seetša”, gomme di ka tlošwa ka
.navbar-dark
.
Dihlogo tša Navbar di bonolo go feta le ge e le neng pele ka lebaka la motswako wa Bootstrap wa diphetogo tša Sass le CSS. Se se sa fetogego ke “navbar ya rena ya seetša” bakeng sa go dirišwa le mebala ya morago e bofefo, eupša o ka dira gape .navbar-dark
le mebala ya morago e lefsifsi. Ka morago ga moo, tlwaetša ka .bg-*
didirišwa.
<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>
Ditshelo
Le ge e le gore ga e nyakege, o ka phuthela navbar ka go a .container
go e bogareng letlakaleng–le ge e le gore ela hloko gore setshelo sa ka gare se sa nyakega. Goba o ka oketša setshelo ka gare ga .navbar
go bogareng fela dikagare tša navbar ya godimo ye e sa fetogego goba ye e sa fetogego .
<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>
Šomiša efe goba efe ya ditshelo tše di arabelago go fetoša gore diteng ka go navbar ya gago di tšweletšwa ka bophara gakaakang.
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-md">
<a class="navbar-brand" href="#">Navbar</a>
</div>
</nav>
Go bewa ga dilo
Diriša didirišwa tša rena tša maemo go bea di-navbar maemong ao e sego a go se fetoge. Kgetha go tšwa go tše di tsepamego go ya godimo, tše di tsepamego fase, di kgomaretše godimo (e kgomarela ka letlakala go fihlela le fihla godimo, ke moka ya dula moo), goba e kgomaretše fase (e kgomarela ka letlakala go fihlela le fihla fase, ke moka ya dula moo).
Fixed navbars use position: fixed
, ho bolela hore ba hula ho tloha phallo e tloaelehileng ea DOM le ka 'na hloka tloaelo CSS (mohlala, padding-top
ka <body>
) ho thibela overlap le elements tse ling.
<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>
Go kgokološa
Oketša .navbar-nav-scroll
go .navbar-nav
(goba karolo ye nngwe ya ka fasana ya navbar) go kgontšha go sepelasepela go ema thwii ka gare ga dikagare tše di fetošwago tša navbar ye e phuhlamego. Ka go ikemela, go kgokološa go a tsena ka 75vh
(goba 75% ya bophagamo bja lefelo la go lebelela), eupša o ka tloša seo ka thepa ya tlwaelo ya CSS ya selegae --bs-navbar-height
goba mekgwa ya tlwaelo. Ka dipono tše kgolo ge navbar e katološwa, diteng di tla tšwelela bjalo ka ge di dira ka go navbar ya go se fetoge.
Hle ela hloko gore boitshwaro bjo bo tla le bofokodi bjo bo ka bago gona bja overflow
—ge go beakanya overflow-y: auto
(go nyakega go kgokološa diteng mo), overflow-x
e lekana le auto
, yeo e tlago go bjala diteng tše dingwe tše di rapaletšego.
Mona ke mohlala navbar sebelisa .navbar-nav-scroll
le style="--bs-scroll-height: 100px;"
, le ba bang ba eketsehileng margin utilities bakeng sa Optimum spacing.
<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>
Maitshwaro a go arabela
Di-navbar di ka šomiša .navbar-toggler
, .navbar-collapse
, le .navbar-expand{-sm|-md|-lg|-xl|-xxl}
diklase go bona gore diteng tša tšona di phuhlama neng ka morago ga konope. Ka kopanyo le didirišwa tše dingwe, o ka kgetha gabonolo gore o tla bontšha neng goba wa uta dielemente tše itšego.
Bakeng sa di-navbar tšeo di sa kego tša phuhlama, oketša .navbar-expand
sehlopha go navbar. Bakeng sa di-navbar tšeo di dulago di phuhlama, o se ke wa oketša .navbar-expand
sehlopha sefe goba sefe.
Sefetoledi sa go fetola
Di-toggler tša Navbar di logagantšwe ka go le letshadi ka go ikemela, eupša ge e ba di swanetše go latela elemente ya ngwanešo go swana le .navbar-brand
, di tla logagantšwe ka go iketla go ya go le letona kudu. Go bušetša morago markup ya gago go tla bušetša morago go bewa ga toggler. Ka tlase ke mehlala ya mekgwa e fapaneng ya toggle.
Ka go se .navbar-brand
bontšhitšwe ka breakpoint ye nnyane kudu:
<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>
Ka leina la leina le le bontšhitšwego ka go le letshadi le toggler ka go le letona:
<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>
Ka toggler ka go le letshadi le leina la leina ka go le letona:
<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>
Diteng tša ka ntle
Ka nako ye nngwe o nyaka go šomiša polaka ya go phuhlama go hlohleletša elemente ya setshelo sa diteng tšeo ka sebopego di dulago ka ntle ga .navbar
. Ka lebaka la gore plugin ya rena e šoma go id
le data-bs-target
go swana, seo se dirwa gabonolo!
<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>
Ge o dira se, re kgothaletša go akaretša JavaScript ya tlaleletšo go šuthiša nepo ka lenaneo go setshelo ge se bulwa. Go sego bjalo, badiriši ba khiiboto le badiriši ba theknolotši ya go thuša go na le kgonagalo ya gore ba tla ba le nako ye thata ya go hwetša diteng tšeo di sa tšwago go utollwa - kudukudu ge e le gore setshelo seo se butšwego se tla pele ga toggler ka sebopegong sa tokumente. Re kgothaletša gape go kgonthiša gore toggler e na le aria-controls
seka, e šupa go id
ya setshelo sa diteng. Ka kgopolo, se se dumelela badiriši ba theknolotši ya go thuša go tlola ka go lebanya go tšwa go toggler go ya go setshelo seo se se laolago–eupša thekgo ya se ga bjale e tloga e le patchy.
Ka ntle ga lešela
Fetoša navbar ya gago ya go katološa le go phuhlama go ba laeborari ya offcanvas ka karolo ya offcanvas . Re katološa bobedi mekgwa ya go se fetoge ya offcanvas gomme re šomiša .navbar-expand-*
diklase tša rena go hlama bara ya ka thoko ya go sepelasepela ye e fetogago le ye e fetofetogago.
Mohlaleng wo o lego ka mo tlase, go hlama navbar ya offcanvas yeo e dulago e phuhlama go ralala le dintlha ka moka tša go kgaotša, tlogela .navbar-expand-*
sehlopha ka botlalo.
<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>
Go hlama navbar ya offcanvas yeo e katološago go navbar ya tlwaelo ka ntlha ye e itšego ya go kgaotša go swana le lg
, šomiša .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>
Ge o šomiša offcanvas ka go navbar ye lefsifsi, ela hloko gore o ka swanelwa ke go ba le mokokotlo wo moso godimo ga diteng tša offcanvas go efoga gore sengwalwa se se balege. Mohlaleng wo o lego ka mo tlase, re tlaleletša .navbar-dark
le .bg-dark
go .navbar
, .text-bg-dark
go .offcanvas
, .dropdown-menu-dark
go .dropdown-menu
, le .btn-close-white
go .btn-close
bakeng sa setaele se se swanetšego ka offcanvas e lefsifsi.
<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
Diphetogo
E okeditšwe ka go v5.2.0Bjalo ka karolo ya go batamela ga diphetogo tša CSS tša Bootstrap tšeo di tšwelelago, di-navbar bjale di diriša diphetogo tša CSS tša lefelong leo godimo .navbar
bakeng sa go tlwaetša ka nako ya kgonthe mo go kaonefaditšwego. Ditekanyetšo tša diphetogo tša CSS di beakantšwe ka Sass, ka fao go tlwaetša Sass go sa thekgwa, le gona.
--#{$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};
Diphetogo tše dingwe tša tlaleletšo tša CSS le tšona di gona go .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);
Tlwaetšo ka diphetogo tša CSS e ka bonwa .navbar-dark
sehlopheng moo re tlošago boleng bjo itšego ntle le go oketša bakgethi ba CSS bao ba ipoeletšago.
--#{$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)};
Diphetogo tša Sass
Diphetogo bakeng sa di-navbar ka moka:
$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;
Diphetogo bakeng sa navbar e lefifi : .
$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 seloupu
Diklase tša go atološa/go phuhlama tša navbar tše di arabelago (mohlala, .navbar-expand-lg
) di kopanywa le $breakpoints
mmapa gomme tša tšweletšwa ka seloupu ka go 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;
}
}
}
}
}
}