Zotsitsa
Sinthani zokulirapo kuti muwonetse mndandanda wamaulalo ndi zina zambiri ndi pulogalamu yowonjezera ya Bootstrap.
Mwachidule
Madontho otsika amatha kusinthika, ndikuwunjikana pazowonetsa mndandanda wamaulalo ndi zina zambiri. Amapangidwa kuti azilumikizana ndi pulogalamu yowonjezera ya Bootstrap ya JavaScript. Amasinthidwa ndikudina, osati kungoyang'ana; ichi ndi chisankho chopanga mwadala .
Zotsitsa zimamangidwa palaibulale ya anthu ena, Popper , yomwe imapereka mawonekedwe osinthika komanso kuzindikira malo owonera. Onetsetsani kuti mukuphatikiza popper.min.js pamaso pa Bootstrap's JavaScript kapena gwiritsani ntchito bootstrap.bundle.min.js
/ bootstrap.bundle.js
yomwe ili ndi Popper. Popper sagwiritsidwa ntchito kuyika zotsikira mu navbars ngakhale kuti kuyimitsidwa kosunthika sikofunikira.
Kufikika
Muyezo wa WAI ARIA umatanthawuza role="menu"
widget yeniyeni , koma iyi ndi mindandanda yazantchito yomwe imayambitsa zochita kapena ntchito. Mindandanda ya ARIA imatha kukhala ndi menyu, zinthu zamabokosi, zinthu za batani la wailesi, magulu a batani la wailesi, ndi ma menyu ang'onoang'ono.
Zotsitsa za Bootstrap, kumbali ina, zidapangidwa kuti zikhale zanthawi zonse komanso zogwiritsidwa ntchito pazosiyanasiyana komanso mawonekedwe. Mwachitsanzo, ndizotheka kupanga zotsitsa zomwe zimakhala ndi zowonjezera ndi zowongolera mawonekedwe, monga malo osakira kapena mafomu olowera. Pazifukwa izi, Bootstrap sayembekezera (kapena kungowonjezera) chilichonse role
mwazofunikira pamamenyu aria-
enieni a ARIA . Olemba akuyenera kuphatikizirapo izi mwapadera iwo eni.
Komabe, Bootstrap imawonjezera chithandizo chokhazikika pazolumikizana zambiri zamakiyibodi, monga kutha kusuntha pazinthu .dropdown-item
zilizonse pogwiritsa ntchito makiyi a cholozera ndikutseka menyu ndi ESCkiyi.
Zitsanzo
Manga chosinthira chotsitsa (batani lanu kapena ulalo) ndi menyu yotsikira mkati .dropdown
, kapena chinthu china chomwe chimalengeza position: relative;
. Zotsitsa zitha kuyambika kuchokera <a>
kapena <button>
zinthu kuti zigwirizane ndi zosowa zanu. Zitsanzo zomwe zasonyezedwa apa zimagwiritsa ntchito ma semantic <ul>
ngati kuli koyenera, koma kuyika kwa makonda kumathandizidwa.
Batani limodzi
Chilichonse .btn
chikhoza kusinthidwa kukhala chotsitsa chotsitsa ndi zosintha zina. Umu ndi momwe mungawagwiritsire ntchito ndi <button>
zinthu zilizonse:
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<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>
</div>
Ndipo ndi <a>
zinthu:
<div class="dropdown">
<a class="btn btn-secondary 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>
</div>
Gawo labwino kwambiri ndikuti mutha kuchita izi ndi batani lililonse, nanunso:
<!-- Example single danger button -->
<div class="btn-group">
<button type="button" class="btn btn-danger dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Action
</button>
<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>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
Kugawa batani
Momwemonso, pangani zotsitsa za batani zogawanika zokhala ndi chizindikiro chofanana ndi mabatani amodzi, koma ndikuwonjezera .dropdown-toggle-split
malo oyenera kuzungulira malo otsikira.
Timagwiritsa ntchito kalasi yowonjezerayi kuti tichepetse zopingasa padding
mbali zonse za chisamaliro ndi 25% ndikuchotsa margin-left
zomwe zimawonjezedwa pamakina otsika. Kusintha kowonjezerako kumapangitsa kuti chisamaliro chikhale chokhazikika mu batani logawanika ndikupereka malo ogunda moyenerera pafupi ndi batani lalikulu.
<!-- Example split danger button -->
<div class="btn-group">
<button type="button" class="btn btn-danger">Action</button>
<button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<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>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
Kukula
Mabatani otsikirapo amagwira ntchito ndi mabatani amitundu yonse, kuphatikiza mabatani otsikirapo ndi ogawanika.
<!-- Large button groups (default and split) -->
<div class="btn-group">
<button class="btn btn-secondary btn-lg dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Large button
</button>
<ul class="dropdown-menu">
...
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary btn-lg" type="button">
Large split button
</button>
<button type="button" class="btn btn-lg btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
...
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Small button
</button>
<ul class="dropdown-menu">
...
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary btn-sm" type="button">
Small split button
</button>
<button type="button" class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
...
</ul>
</div>
Zotsitsa zakuda
Sankhani zotsitsa zakuda kuti mufanane ndi navbar yakuda kapena masitayilo anu powonjezera .dropdown-menu-dark
pa .dropdown-menu
. Palibe zosintha zomwe zimafunikira pazotsitsa.
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu dropdown-menu-dark">
<li><a class="dropdown-item active" 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>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
Ndipo kuyiyika kuti igwiritsidwe ntchito mu navbar:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDarkDropdown" aria-controls="navbarNavDarkDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDarkDropdown">
<ul class="navbar-nav">
<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><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
Mayendedwe
RTL
Mayendedwe amawonetsedwa mukamagwiritsa ntchito Bootstrap mu RTL, kutanthauza .dropstart
kuti kudzawoneka kumanja.
Pakati
Pangani menyu yotsikirayo kukhala pansi pakusintha ndi .dropdown-center
chinthu cha makolo.
<div class="dropdown-center">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Centered dropdown
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Action two</a></li>
<li><a class="dropdown-item" href="#">Action three</a></li>
</ul>
</div>
Kusiya
Yambitsani mindandanda yotsikira pamwamba pa zinthu powonjezera .dropup
ku chinthu cha makolo.
<!-- Default dropup button -->
<div class="btn-group dropup">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropup
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
<!-- Split dropup button -->
<div class="btn-group dropup">
<button type="button" class="btn btn-secondary">
Split dropup
</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
Dropup pakati
Pangani menyu yotsitsa kukhala pamwamba pakusintha ndi .dropup-center
chinthu cha makolo.
<div class="dropup-center dropup">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Centered dropup
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Action two</a></li>
<li><a class="dropdown-item" href="#">Action three</a></li>
</ul>
</div>
Dontho
Yambitsani mindandanda yotsikira kumanja kwa zinthu powonjezera .dropend
ku chinthu cha makolo.
<!-- Default dropend button -->
<div class="btn-group dropend">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropend
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
<!-- Split dropend button -->
<div class="btn-group dropend">
<button type="button" class="btn btn-secondary">
Split dropend
</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropend</span>
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
Dropstart
Yambitsani mindandanda yotsikira kumanzere kwa zinthu powonjezera .dropstart
ku chinthu cha makolo.
<!-- Default dropstart button -->
<div class="btn-group dropstart">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropstart
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
<!-- Split dropstart button -->
<div class="btn-group dropstart">
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropstart</span>
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
<button type="button" class="btn btn-secondary">
Split dropstart
</button>
</div>
Zinthu za menyu
Mutha kugwiritsa ntchito zinthu <a>
kapena <button>
zinthu ngati zotsitsa.
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</button>
<ul class="dropdown-menu">
<li><button class="dropdown-item" type="button">Action</button></li>
<li><button class="dropdown-item" type="button">Another action</button></li>
<li><button class="dropdown-item" type="button">Something else here</button></li>
</ul>
</div>
Mutha kupanganso zinthu zotsikirako zosagwiritsa ntchito ndi .dropdown-item-text
. Khalani omasuka kuti muwonjezere mawonekedwe ndi CSS kapena zolemba.
<ul class="dropdown-menu">
<li><span class="dropdown-item-text">Dropdown item text</span></li>
<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>
Yogwira
Onjezani .active
kuzinthu zomwe zili m'munsi kuti ziwoneke ngati zikugwira ntchito . Kuti mufotokozere zomwe zikuchitika ku matekinoloje othandizira, gwiritsani ntchito aria-current
chidziwitsocho - pogwiritsa ntchito page
mtengo watsamba lomwe lili pano, kapena zomwe true
zili patsamba lino.
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Regular link</a></li>
<li><a class="dropdown-item active" href="#" aria-current="true">Active link</a></li>
<li><a class="dropdown-item" href="#">Another link</a></li>
</ul>
Wolumala
Onjezani .disabled
kuzinthu zomwe zili m'munsimu kuti zikhale ngati zolephereka .
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Regular link</a></li>
<li><a class="dropdown-item disabled">Disabled link</a></li>
<li><a class="dropdown-item" href="#">Another link</a></li>
</ul>
Kusintha kwa menyu
Mwachikhazikitso, menyu yotsitsa imayikidwa 100% kuchokera pamwamba ndi kumanzere kwa kholo lake. Mutha kusintha izi ndi .drop*
makalasi owongolera, koma mutha kuwawongoleranso ndi makalasi owonjezera osintha.
Onjezani .dropdown-menu-end
ku a .dropdown-menu
kulumikiza kumanja menyu yotsitsa. Mayendedwe amawonetsedwa mukamagwiritsa ntchito Bootstrap mu RTL, kutanthauza .dropdown-menu-end
kuti kudzawonekera kumanzere.
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Right-aligned menu example
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><button class="dropdown-item" type="button">Action</button></li>
<li><button class="dropdown-item" type="button">Another action</button></li>
<li><button class="dropdown-item" type="button">Something else here</button></li>
</ul>
</div>
Mayalikidwe omvera
Ngati mukufuna kugwiritsa ntchito kuyanjanitsa komvera, zimitsani mawonekedwe osinthika powonjezera mawonekedwe data-bs-display="static"
ndikugwiritsa ntchito makalasi omvera.
Kuti muyanjanitse menyu yotsikirayo ndi malo omwe mwapatsidwa kapena okulirapo, onjezani .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-end
.
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
Left-aligned but right aligned when large screen
</button>
<ul class="dropdown-menu dropdown-menu-lg-end">
<li><button class="dropdown-item" type="button">Action</button></li>
<li><button class="dropdown-item" type="button">Another action</button></li>
<li><button class="dropdown-item" type="button">Something else here</button></li>
</ul>
</div>
Kuti muyanjanitse kumanzere menyu yotsitsa ndi malo omwe mwapatsidwa kapena okulirapo, onjezani .dropdown-menu-end
ndi .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-start
.
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
Right-aligned but left aligned when large screen
</button>
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-lg-start">
<li><button class="dropdown-item" type="button">Action</button></li>
<li><button class="dropdown-item" type="button">Another action</button></li>
<li><button class="dropdown-item" type="button">Something else here</button></li>
</ul>
</div>
Zindikirani kuti simukuyenera kuwonjezera mawonekedwe data-bs-display="static"
pamabatani otsitsa mu navbars, popeza Popper sagwiritsidwa ntchito mu navbars.
Zosankha za kuyanjanitsa
Potengera zambiri zomwe zasonyezedwa pamwambapa, nayi chiwonetsero chazolowera m'khitchini chamitundu yosiyanasiyana yotsitsa pamalo amodzi.
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Right-aligned menu
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
Left-aligned, right-aligned lg
</button>
<ul class="dropdown-menu dropdown-menu-lg-end">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
Right-aligned, left-aligned lg
</button>
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-lg-start">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group dropstart">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropstart
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group dropend">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropend
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group dropup">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropup
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
Zomwe zili pamenyu
Mitu
Onjezani mutu kuti mulembe magawo a zochita mu menyu yotsikira.
<ul class="dropdown-menu">
<li><h6 class="dropdown-header">Dropdown header</h6></li>
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
</ul>
Ogawanitsa
Olekanitsa magulu azinthu zokhudzana ndi menyu ndi chogawa.
<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>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
Mawu
Ikani mawu aliwonse aulere mkati mwa menyu otsika omwe ali ndi mawu ndikugwiritsa ntchito masitayilo . Dziwani kuti mudzafunika masitayelo owonjezera kuti muchepetse kukula kwa menyu.
<div class="dropdown-menu p-4 text-muted" style="max-width: 200px;">
<p>
Some example text that's free-flowing within the dropdown menu.
</p>
<p class="mb-0">
And this is more example text.
</p>
</div>
Mafomu
Ikani fomu mkati mwa menyu yotsitsa, kapena ipangitseni kukhala menyu yotsitsa, ndipo gwiritsani ntchito malire kapena ma padding kuti mupatse malo omwe mukufuna.
<div class="dropdown-menu">
<form class="px-4 py-3">
<div class="mb-3">
<label for="exampleDropdownFormEmail1" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleDropdownFormEmail1" placeholder="[email protected]">
</div>
<div class="mb-3">
<label for="exampleDropdownFormPassword1" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleDropdownFormPassword1" placeholder="Password">
</div>
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="dropdownCheck">
<label class="form-check-label" for="dropdownCheck">
Remember me
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">New around here? Sign up</a>
<a class="dropdown-item" href="#">Forgot password?</a>
</div>
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="outside">
Dropdown form
</button>
<form class="dropdown-menu p-4">
<div class="mb-3">
<label for="exampleDropdownFormEmail2" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleDropdownFormEmail2" placeholder="[email protected]">
</div>
<div class="mb-3">
<label for="exampleDropdownFormPassword2" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleDropdownFormPassword2" placeholder="Password">
</div>
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="dropdownCheck2">
<label class="form-check-label" for="dropdownCheck2">
Remember me
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
</div>
Zosankha zotsitsa
Gwiritsani ntchito data-bs-offset
kapena data-bs-reference
kusintha malo otsitsa.
<div class="d-flex">
<div class="dropdown me-1">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" data-bs-offset="10,20">
Offset
</button>
<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>
</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary">Reference</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false" data-bs-reference="parent">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<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>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
</div>
Khalidwe lotseka basi
Mwachikhazikitso, menyu yotsitsa imatsekedwa mukadina mkati kapena kunja kwa menyu yotsitsa. Mutha kugwiritsa ntchito autoClose
mwayiwu kuti musinthe machitidwe otsitsa.
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="true" aria-expanded="false">
Default dropdown
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="inside" aria-expanded="false">
Clickable outside
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
Clickable inside
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-auto-close="false" aria-expanded="false">
Manual close
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
<li><a class="dropdown-item" href="#">Menu item</a></li>
</ul>
</div>
CSS
Zosintha
Yowonjezedwa mu v5.2.0Monga gawo la njira yosinthira ya CSS ya Bootstrap, zotsitsa tsopano zimagwiritsa ntchito zosintha za CSS zakumaloko .dropdown-menu
kuti zisinthidwe zenizeni zenizeni. Makhalidwe amitundu ya CSS amayikidwa kudzera pa Sass, kotero makonda a Sass akadali othandizidwa, nawonso.
--#{$prefix}dropdown-zindex: #{$zindex-dropdown};
--#{$prefix}dropdown-min-width: #{$dropdown-min-width};
--#{$prefix}dropdown-padding-x: #{$dropdown-padding-x};
--#{$prefix}dropdown-padding-y: #{$dropdown-padding-y};
--#{$prefix}dropdown-spacer: #{$dropdown-spacer};
@include rfs($dropdown-font-size, --#{$prefix}dropdown-font-size);
--#{$prefix}dropdown-color: #{$dropdown-color};
--#{$prefix}dropdown-bg: #{$dropdown-bg};
--#{$prefix}dropdown-border-color: #{$dropdown-border-color};
--#{$prefix}dropdown-border-radius: #{$dropdown-border-radius};
--#{$prefix}dropdown-border-width: #{$dropdown-border-width};
--#{$prefix}dropdown-inner-border-radius: #{$dropdown-inner-border-radius};
--#{$prefix}dropdown-divider-bg: #{$dropdown-divider-bg};
--#{$prefix}dropdown-divider-margin-y: #{$dropdown-divider-margin-y};
--#{$prefix}dropdown-box-shadow: #{$dropdown-box-shadow};
--#{$prefix}dropdown-link-color: #{$dropdown-link-color};
--#{$prefix}dropdown-link-hover-color: #{$dropdown-link-hover-color};
--#{$prefix}dropdown-link-hover-bg: #{$dropdown-link-hover-bg};
--#{$prefix}dropdown-link-active-color: #{$dropdown-link-active-color};
--#{$prefix}dropdown-link-active-bg: #{$dropdown-link-active-bg};
--#{$prefix}dropdown-link-disabled-color: #{$dropdown-link-disabled-color};
--#{$prefix}dropdown-item-padding-x: #{$dropdown-item-padding-x};
--#{$prefix}dropdown-item-padding-y: #{$dropdown-item-padding-y};
--#{$prefix}dropdown-header-color: #{$dropdown-header-color};
--#{$prefix}dropdown-header-padding-x: #{$dropdown-header-padding-x};
--#{$prefix}dropdown-header-padding-y: #{$dropdown-header-padding-y};
Kusintha mwamakonda kudzera mumitundu ya CSS kumatha kuwoneka .dropdown-menu-dark
m'kalasi momwe timapitilira zinthu zina popanda kuwonjezera ma CSS osankhidwa.
--#{$prefix}dropdown-color: #{$dropdown-dark-color};
--#{$prefix}dropdown-bg: #{$dropdown-dark-bg};
--#{$prefix}dropdown-border-color: #{$dropdown-dark-border-color};
--#{$prefix}dropdown-box-shadow: #{$dropdown-dark-box-shadow};
--#{$prefix}dropdown-link-color: #{$dropdown-dark-link-color};
--#{$prefix}dropdown-link-hover-color: #{$dropdown-dark-link-hover-color};
--#{$prefix}dropdown-divider-bg: #{$dropdown-dark-divider-bg};
--#{$prefix}dropdown-link-hover-bg: #{$dropdown-dark-link-hover-bg};
--#{$prefix}dropdown-link-active-color: #{$dropdown-dark-link-active-color};
--#{$prefix}dropdown-link-active-bg: #{$dropdown-dark-link-active-bg};
--#{$prefix}dropdown-link-disabled-color: #{$dropdown-dark-link-disabled-color};
--#{$prefix}dropdown-header-color: #{$dropdown-dark-header-color};
Zosintha za Sass
Zosintha zamitundu yonse:
$dropdown-min-width: 10rem;
$dropdown-padding-x: 0;
$dropdown-padding-y: .5rem;
$dropdown-spacer: .125rem;
$dropdown-font-size: $font-size-base;
$dropdown-color: $body-color;
$dropdown-bg: $white;
$dropdown-border-color: var(--#{$prefix}border-color-translucent);
$dropdown-border-radius: $border-radius;
$dropdown-border-width: $border-width;
$dropdown-inner-border-radius: subtract($dropdown-border-radius, $dropdown-border-width);
$dropdown-divider-bg: $dropdown-border-color;
$dropdown-divider-margin-y: $spacer * .5;
$dropdown-box-shadow: $box-shadow;
$dropdown-link-color: $gray-900;
$dropdown-link-hover-color: shade-color($dropdown-link-color, 10%);
$dropdown-link-hover-bg: $gray-200;
$dropdown-link-active-color: $component-active-color;
$dropdown-link-active-bg: $component-active-bg;
$dropdown-link-disabled-color: $gray-500;
$dropdown-item-padding-y: $spacer * .25;
$dropdown-item-padding-x: $spacer;
$dropdown-header-color: $gray-600;
$dropdown-header-padding-x: $dropdown-item-padding-x;
$dropdown-header-padding-y: $dropdown-padding-y;
// fusv-disable
$dropdown-header-padding: $dropdown-header-padding-y $dropdown-header-padding-x; // Deprecated in v5.2.0
// fusv-enable
Zosintha zamtundu wakuda :
$dropdown-dark-color: $gray-300;
$dropdown-dark-bg: $gray-800;
$dropdown-dark-border-color: $dropdown-border-color;
$dropdown-dark-divider-bg: $dropdown-divider-bg;
$dropdown-dark-box-shadow: null;
$dropdown-dark-link-color: $dropdown-dark-color;
$dropdown-dark-link-hover-color: $white;
$dropdown-dark-link-hover-bg: rgba($white, .15);
$dropdown-dark-link-active-color: $dropdown-link-active-color;
$dropdown-dark-link-active-bg: $dropdown-link-active-bg;
$dropdown-dark-link-disabled-color: $gray-500;
$dropdown-dark-header-color: $gray-500;
Zosintha zapa CSS-based carets zomwe zikuwonetsa kuyanjana kwatsike:
$caret-width: .3em;
$caret-vertical-align: $caret-width * .85;
$caret-spacing: $caret-width * .85;
Zosakaniza
Mixins amagwiritsidwa ntchito popanga ma CSS-based carets ndipo amapezeka mu scss/mixins/_caret.scss
.
@mixin caret-down {
border-top: $caret-width solid;
border-right: $caret-width solid transparent;
border-bottom: 0;
border-left: $caret-width solid transparent;
}
@mixin caret-up {
border-top: 0;
border-right: $caret-width solid transparent;
border-bottom: $caret-width solid;
border-left: $caret-width solid transparent;
}
@mixin caret-end {
border-top: $caret-width solid transparent;
border-right: 0;
border-bottom: $caret-width solid transparent;
border-left: $caret-width solid;
}
@mixin caret-start {
border-top: $caret-width solid transparent;
border-right: $caret-width solid;
border-bottom: $caret-width solid transparent;
}
@mixin caret($direction: down) {
@if $enable-caret {
&::after {
display: inline-block;
margin-left: $caret-spacing;
vertical-align: $caret-vertical-align;
content: "";
@if $direction == down {
@include caret-down();
} @else if $direction == up {
@include caret-up();
} @else if $direction == end {
@include caret-end();
}
}
@if $direction == start {
&::after {
display: none;
}
&::before {
display: inline-block;
margin-right: $caret-spacing;
vertical-align: $caret-vertical-align;
content: "";
@include caret-start();
}
}
&:empty::after {
margin-left: 0;
}
}
}
Kugwiritsa ntchito
Pogwiritsa ntchito mawonekedwe a data kapena JavaScript, pulogalamu yowonjezera yotsitsa imasintha zobisika (mindandanda yotsitsa) posintha .show
kalasi pa kholo .dropdown-menu
. Lingaliroli data-bs-toggle="dropdown"
limadaliridwa potseka mindandanda yazakudya pamlingo wogwiritsa ntchito, ndiye ndibwino kuti muzigwiritsa ntchito nthawi zonse.
mouseover
kwa ana omwe ali nawo
<body>
. Kuthyolako
kovomerezeka kumeneku ndikofunikira kuti mugwiritse ntchito movutikira muutumiki wa zochitika za iOS , zomwe zingalepheretse kugunda kulikonse kunja kwa dontho kuti zisayambitse khodi yomwe imatseka kutsitsa. Kutsitsa kukatsekedwa, zowongolera zopanda kanthu
mouseover
izi zimachotsedwa.
Kudzera muzochita za data
Onjezani data-bs-toggle="dropdown"
ku ulalo kapena batani kuti musinthe kutsitsa.
<div class="dropdown">
<button type="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown trigger
</button>
<ul class="dropdown-menu">
...
</ul>
</div>
Kudzera pa JavaScript
Imbani zotsitsa kudzera pa JavaScript:
const dropdownElementList = document.querySelectorAll('.dropdown-toggle')
const dropdownList = [...dropdownElementList].map(dropdownToggleEl => new bootstrap.Dropdown(dropdownToggleEl))
data-bs-toggle="dropdown"
zofunikabe
Mosasamala kanthu kuti mumayitanira kutsika kwanu kudzera pa JavaScript kapena m'malo mwake mugwiritse ntchito data-api, data-bs-toggle="dropdown"
nthawi zonse imafunika kuti mukhalepo pazoyambitsa zotsitsa.
Zosankha
Monga zosankha zitha kuperekedwa kudzera pa data kapena JavaScript, mutha kuwonjezera dzina lachisankho ku data-bs-
, monga data-bs-animation="{value}"
. Onetsetsani kuti musinthe mtundu wamtundu wa dzina lachisankho kuchokera ku " camelCase " kupita ku " kebab-case " podutsa zosankha pogwiritsa ntchito zizindikiro za data. Mwachitsanzo, gwiritsani ntchito data-bs-custom-class="beautifier"
m'malo mwa data-bs-customClass="beautifier"
.
Kuyambira pa Bootstrap 5.2.0, zigawo zonse zimathandizira chidziwitso chosungidwa cha data data-bs-config
chomwe chingathe kukhazikitsa chigawo chosavuta ngati chingwe cha JSON. Chilichonse chikakhala ndi mawonekedwe , mtengo womaliza udzakhala ndipo mawonekedwe osiyana a data adzapitilira zomwe zaperekedwa data-bs-config='{"delay":0, "title":123}'
pa . Kuphatikiza apo, zomwe zilipo kale zimatha kusunga ma JSON monga .data-bs-title="456"
title
456
data-bs-config
data-bs-delay='{"show":0,"hide":150}'
Dzina | Mtundu | Zosasintha | Kufotokozera |
---|---|---|---|
autoClose |
boolean, chingwe | true |
Konzani machitidwe otsekera otsikirapo:
|
boundary |
chingwe, element | 'clippingParents' |
Malire oletsa kusefukira a menyu otsikira (amangokhudza Popper's preventOverflow modifier). Mwachikhazikitso ndi clippingParents ndipo imatha kuvomereza HTMLElement reference (kudzera JavaScript kokha). Kuti mudziwe zambiri onani zolemba za Popper's detectOverflow . |
display |
chingwe | 'dynamic' |
Mwachikhazikitso, timagwiritsa ntchito Popper poyimitsa ma dynamic positioning. Letsani izi ndi static . |
offset |
gulu, chingwe, ntchito | [0, 2] |
Kuchotsera kwa dontho lotsika poyerekeza ndi chandamale chake. Mutha kudutsa zingwe zama data okhala ndi ma comma olekanitsidwa monga: data-bs-offset="10,20" . Ntchito ikagwiritsidwa ntchito kutsimikizira kuchotsera, imatchedwa ndi chinthu chomwe chili ndi popper, zolozera, ndi popper rects ngati mkangano wake woyamba. Choyambitsa chinthu cha DOM node chimadutsa ngati mkangano wachiwiri. Ntchitoyi iyenera kubweza mndandanda wokhala ndi manambala awiri: skidding , mtunda . Kuti mumve zambiri onani za Popper's offset docs . |
popperConfig |
null, chinthu, ntchito | null |
Kuti musinthe kasinthidwe ka Popper ka Bootstrap, onani kasinthidwe ka Popper . Ntchito ikagwiritsidwa ntchito kupanga masinthidwe a Popper, imatchedwa ndi chinthu chomwe chili ndi kasinthidwe ka Popper ka Bootstrap. Zimakuthandizani kugwiritsa ntchito ndikuphatikiza zokhazikika ndi kasinthidwe kanu. Ntchitoyi iyenera kubweza chinthu chosinthira cha Popper. |
reference |
chingwe, chinthu, chinthu | 'toggle' |
Cholozera cha menyu otsika. Imavomereza mfundo za 'toggle' , 'parent' , HTMLElement reference kapena chinthu chopereka getBoundingClientRect . Kuti mumve zambiri onani zolemba za Popper's constructor docs ndi ma virtual element docs . |
Kugwiritsa ntchito ndipopperConfig
const dropdown = new bootstrap.Dropdown(element, {
popperConfig(defaultBsPopperConfig) {
// const newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Njira
Njira | Kufotokozera |
---|---|
dispose |
Imawononga kutsika kwa chinthu. (Imachotsa deta yosungidwa pa chinthu cha DOM) |
getInstance |
Njira yosasunthika yomwe imakupatsani mwayi wotsitsa wolumikizidwa ndi chinthu cha DOM, mutha kuchigwiritsa ntchito motere: bootstrap.Dropdown.getInstance(element) . |
getOrCreateInstance |
Njira yosasunthika yomwe imabweretsanso chinthu chotsika cholumikizidwa ndi chinthu cha DOM kapena kupanga china china ngati sichinayambike. Mutha kugwiritsa ntchito motere bootstrap.Dropdown.getOrCreateInstance(element) :. |
hide |
Imabisa menyu yotsikira ya navbar yoperekedwa kapena kusakatula kwa tabu. |
show |
Imawonetsa menyu otsikira a navbar yopatsidwa kapena navigation ya tabbed. |
toggle |
Imatembenuza menyu yotsikira ya navbar yopatsidwa kapena kusakatula kwa tabu. |
update |
Imawonjezera pomwe pali kutsika kwa chinthu. |
Zochitika
Zochitika zonse zotsitsa zimawomberedwa pa toggling element kenako ndikuwomberedwa. Kotero inu mukhoza kuwonjezera omvera zochitika pa .dropdown-menu
's kholo element. hide.bs.dropdown
ndipo hidden.bs.dropdown
zochitika zimakhala ndi clickEvent
katundu (pokhapo pamene mtundu wa Chochitika choyambirira uli click
) chomwe chili ndi Chochitika Chochitika cha chochitikacho.
Mtundu wa chochitika | Kufotokozera |
---|---|
hide.bs.dropdown |
Kuyatsa nthawi yomweyo hide njira yachitsanzo itayitanidwa. |
hidden.bs.dropdown |
Kuthamangitsidwa pamene dontho latha kubisidwa kwa wogwiritsa ntchito ndipo kusintha kwa CSS kwatha. |
show.bs.dropdown |
Kuyatsa nthawi yomweyo show njira yachitsanzo itayitanidwa. |
shown.bs.dropdown |
Kuwotchedwa pamene dontho lakhala likuwonekera kwa wogwiritsa ntchito ndipo kusintha kwa CSS kwatha. |
const myDropdown = document.getElementById('myDropdown')
myDropdown.addEventListener('show.bs.dropdown', event => {
// do something...
})