Navbar
Bootstrap-yň güýçli, täsirli nawigasiýa sözbaşy, deňiz paneli üçin resminamalar we mysallar. Marka, nawigasiýa, çökmek plugin we ş.m. goldawy öz içine alýar.
Bu nähili işleýär
Deňiz paneli bilen başlamazdan ozal bilmeli zatlaryňyz:
- Gämi duralgalary täsirli çökmek we reňk shemasy sapaklary üçin
.navbar
örtük talap edýär ..navbar-expand{-sm|-md|-lg|-xl}
- Gämi duralgalary we olaryň mazmuny adaty ýagdaýda suwukdyr. Gorizontal giňligini çäklendirmek üçin goşmaça gaplary ulanyň .
- Deňiz panelleriniň arasyndaky aralygy we deňleşmegi dolandyrmak üçin aralyk we flex peýdaly synplarymyzy ulanyň .
- Gämi duralgalary adaty ýagdaýda jogap berýär, ýöne muny üýtgetmek üçin aňsatlyk bilen üýtgedip bilersiňiz. Jogapkärçilikli hereket, “Collapse JavaScript” pluginimize baglydyr.
- Gämi duralgalary çap edilende gizlenýär. Goşmak arkaly olary çap
.d-print
etmäge mejbur ediň.navbar
. Ekranyň peýdaly synpyna serediň . - Bir elementi ulanyp elýeterliligi üpjün ediň
<nav>
ýa-da a ýaly has umumy elementi ulanýan bolsaňyz , kömekçi tehnologiýalary ulanýanlar üçin möhüm sebit hökmünde aç-açan kesgitlemek üçin her bir deňiz paneline<div>
goşuň .role="navigation"
prefers-reduced-motion
media talaplaryna baglydyr. Elýeterlilik resminamalarymyzyň azaldylan hereket bölümine serediň
.
Goldanýan mazmun
Gämi duralgalary az sanly kiçi komponentler üçin içerki goldaw bilen gelýär. Zerur bolanda aşakdakylardan saýlaň:
.navbar-brand
kompaniýaňyz, önümiňiz ýa-da taslama adyňyz üçin..navbar-nav
doly beýik we ýeňil nawigasiýa üçin (aşak düşýänlere goldaw goşmak bilen)..navbar-toggler
ýykylýan pluginimiz we beýleki nawigasiýa hereketlerini üýtgetmek üçin ulanmak üçin..form-inline
islendik görnüşdäki gözegçilik we hereketler üçin..navbar-text
dikligine merkezleşdirilen tekstleri goşmak üçin..collapse.navbar-collapse
ene-atanyň nokady boýunça navbar mazmunyny toparlaşdyrmak we gizlemek üçin.
lg
Ine, (uly) kesiş nokadynda awtomatiki ýykylýan täsirli ýagtylyk temaly deňiz paneline girizilen ähli kiçi komponentleriň mysaly .
<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>
Bu mysalda reňk ( bg-light
) we aralyk ( my-2
,,, ) my-lg-0
peýdaly synplar ulanylýar mr-sm-0
.my-sm-0
Marka
Bu .navbar-brand
element köp elementlere ulanylyp bilner, ýöne labyr iň oňat işleýär, sebäbi käbir elementler peýdaly synplary ýa-da adaty stilleri talap edip biler.
<!-- 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>
Şekilleri islege goşmak, .navbar-brand
elmydama dogry ölçeg üçin adaty stilleri ýa-da kömekçi enjamlary talap eder. Ine görkezmek üçin käbir mysallar.
<!-- 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 nawigasiýa baglanyşyklary .nav
, öz üýtgediji synpy bilen opsiýalarymyzda gurulýar we dogry jogap bermek üçin açyk synplary ulanmagy talap edýär. Deňiz panellerindäki nawigasiýa, deňiz paneliňiziň mazmunyny ygtybarly sazlamak üçin mümkin boldugyça gorizontal giňişligi eýeleýär .
Işjeň ýagdaýlar , häzirki sahypany göni ýa-da ýakyn ene-atalaryna .active
ulanyp boljakdygyny görkezmek üçin ..nav-link
.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>
Deňiz güýçlerimiz üçin sapaklary ulanýandygymyz sebäpli, isleseňiz sanaw esasly çemeleşmeden doly gaçyp bilersiňiz.
<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ýle hem, deňiz paneliňizdäki açylan ýerleri ulanyp bilersiňiz. Açylýan menýular ýerleşdirmek üçin örtük elementini talap edýär, şonuň üçin aşakda görkezilişi ýaly aýratyn .nav-item
we ýerleşdirilen elementleri ulanmagy unutmaň..nav-link
<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>
Formalar
Dürli forma dolandyryşlaryny we böleklerini deňiz panelinde ýerleşdiriň .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>
.navbar
Flex düzülişini ulanmagyň derrew çaga elementleri justify-content: space-between
. Bu özüni alyp barşy sazlamak üçin goşmaça flex enjamlaryny ulanyň.
<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>
Giriş toparlary hem işleýär:
<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>
Bu düwme görnüşleriniň bir bölegi hökmünde dürli düwmeler hem goldanýar. Bu, wertikal deňleşdiriş enjamlarynyň dürli ululykdaky elementleri deňleşdirmek üçin ulanylyp bilinjekdigini hem ýatladýar.
<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>
Tekst
Gämi duralgalarynyň kömegi bilen bir topar tekst bolup biler .navbar-text
. Bu synp tekstiň setirleri üçin dik tekizlemäni we keseligine aralygy sazlaýar.
<nav class="navbar navbar-light bg-light">
<span class="navbar-text">
Navbar text with an inline element
</span>
</nav>
Zerur bolanda beýleki komponentler we kömekçi enjamlar bilen garyşdyryň we gabat geliň.
<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>
Reňk shemalary
Deňiz panelini ýylatmak, mowzuk sapaklarynyň we kömekçi enjamlaryň utgaşmasy netijesinde hiç haçan aňsat bolmady background-color
. .navbar-light
Açyk fon reňkleri ýa-da goýy fon reňkleri üçin saýlaň .navbar-dark
. Soň bolsa, .bg-*
kömekçi enjamlar bilen sazlaň.
<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>
Konteýnerler
.container
Gerek däl bolsa- da, bir sahypada merkezleşdirmek üçin deňiz panelini örtüp bilersiňiz. Ora-da diňe durnukly ýa-da statiki ýokarky gämi duralgasynyň.navbar
mazmunyny merkezleşdirmek üçin bir konteýner goşup bilersiňiz .
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
</nav>
</div>
.navbar-expand{-sm|-md|-lg|-xl}
Konteýner deňiz paneliňizde bolsa, gorizontal padding görkezilen synpyňyzdan pes nokatlarda aýrylýar . Deňiz paneli ýykylanda aşaky görnüşdäki ýerlere gereksiz ýerleşdirmekligi iki esse artdyrmaýarys.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">Navbar</a>
</div>
</nav>
Acementerleşiş
Deňiz panellerini statik däl ýerlerde ýerleşdirmek üçin pozisiýa hyzmatlarymyzy ulanyň . Fixedokardan ýokarsyna, aşagyna berkidilen ýa-da ýokarsyna berkidilenini saýlaň (sahypa ýokarsyna ýetýänçä aýlaň, soňra şol ýerde galar). Kesgitli gämi duralgalary ulanylýar position: fixed
, ýagny DOM-yň adaty akymyndan çekilýär we beýleki elementler bilen gabat gelmezligi üçin ýörite CSS talap edip biler (mysal padding-top
üçin ).<body>
Şeýle hem , her brauzerde doly goldanmaýan.sticky-top
ulanylyşynaposition: sticky
üns beriň .
<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>
Aýlamak
.navbar-nav-scroll
Aykylan deňiz paneliniň üýtgäp bilýän mazmunynyň içinde dik aýlanmagy üpjün etmek üçin .navbar-collapse
(ýa-da beýleki deňiz paneli kiçi komponentine) goşuň . Düzgüne görä, aýlamak 75vh
(ýa-da görüniş beýikliginiň 75%) başlaýar, ýöne içerki ýa-da adaty görnüşler bilen muny ýok edip bilersiňiz. Deňiz paneli giňeldilende has uly görnüşlerde mazmun, adaty deňiz panelinde bolşy ýaly peýda bolar.
Bu özüni alyp barşyň potensial kemçilikleri bilen ýüze çykýandygyny ýadyňyzdan çykarmaň - overflow
sazlamalar overflow-y: auto
(mazmuny şu ýere aýlamak üçin zerur), gorizontal mazmuny kesjek overflow-x
ekwiwalentdir .auto
Ine, iň oňat aralyk üçin goşmaça margin enjamlary bilen .navbar-nav-scroll
ulanylýan navbar paneli.style="max-height: 100px;"
<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>
Jogapkärçilikli özüni alyp baryş
Gämi duralgalary mazmunynyň bir düwmäniň aňyrsynda haçan ýykylýandygyny kesgitlemek üçin .navbar-toggler
ulanyp bilerler . Beýleki kömekçi enjamlar bilen bilelikde belli elementleri haçan görkezmelidigini ýa-da gizlemelidigini aňsatlyk bilen saýlap bilersiňiz..navbar-collapse
.navbar-expand{-sm|-md|-lg|-xl}
Hiç haçan ýykylmaýan gämi duralgalary üçin, deňiz paneline .navbar-expand
synp goşuň. Elmydama ýykylýan gämi duralgalary üçin hiç hili .navbar-expand
synp goşmaň.
Toggler
Navbar açarlary adaty ýagdaýda çep hatara düzülendir, ýöne a ýaly dogan elementine eýerseler, .navbar-brand
awtomatiki usulda sag tarapa deňleşerler. Belgiňizi yzyna öwürmek, geçirijiniň ýerleşdirilmegini tersleşdirer. Aşakda dürli üýtgetmek stilleriniň mysallary getirilýär.
Iň .navbar-brand
kiçi nokatda görkezilmedi:
<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>
Çepde görkezilen marka ady we sag tarapda üýtgetmek:
<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>
Çepde açar we sagda marka ady bilen:
<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>
Daşarky mazmun
Käwagt strukturalaýyn daşynda ýerleşýän mazmun üçin konteýner elementini işletmek üçin çökmek plaginini ulanmak isleýärsiňiz .navbar
. Biziň pluginimiz gabat gelýän id
we data-target
işleýänligi sebäpli, aňsatlyk bilen ýerine ýetirilýär!
<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>
Muny ýerine ýetireniňizde, fokus açylanda konteýnerine programma taýdan geçirmek üçin goşmaça JavaScript goşmagy maslahat berýäris. Otherwiseogsam, klawiaturany ulanýanlar we kömekçi tehnologiýalary ulanýanlar täze açylan mazmuny tapmakda kynçylyk çekerler - esasanam açylan konteýner resminamanyň gurluşynda açylmazdan ozal . Mundan başga-da, göçürijiniň mazmun konteýneriniň mazmunyny aria-controls
görkezip , häsiýetiniň bardygyna göz ýetirmegi maslahat berýäris . id
Teoriýa boýunça, bu kömekçi tehnologiýa ulanyjylaryna gönüden-göni gözegçilikden geçirýän konteýnerine bökmäge mümkinçilik berýär - ýöne häzirki wagtda bu goldaw gaty kyn.