Drɔpdɔwn dɛn
Tɔgl kɔntɛkstual ɔvlay fɔ sho list dɛn fɔ link dɛn ɛn mɔ wit di Bootstrap drɔpdɔwn plɔgin.
Ɔvaviu fɔ di Baybul
Drɔpdɔwn dɛn kin chenj, kɔntɛkstual ɔvlay fɔ sho list dɛn fɔ link dɛn ɛn ɔda tin dɛn. Dɛn mek dɛn intaraktiv wit di Bootstrap drɔpdɔwn JavaSkript plɔgin we de insay. Dɛn kin toggl dɛn bay we dɛn de klik, nɔto bay we dɛn de hov; dis na wan intenshɔnal dizayn disizhɔn .
Dɛn bil drɔpdɔwn dɛn pan wan tɔd pati laybri, Popper , we de gi dinamik pozishɔn ɛn viupɔt ditekshɔn. Mek shɔ se yu put popper.min.js bifo Bootstrap in JavaSkript ɔ yuz bootstrap.bundle.min.js
/ bootstrap.bundle.js
we gɛt Popper. Popper nɔ yuz fɔ posishun drɔpdɔwn dɛn na navbar dɛn pan ɔl we as dinamik pozishɔn nɔ nid.
Di we aw pɔsin kin ebul fɔ go de
Di WAI ARIA standad de difayn wan aktual role="menu"
widget , bɔt dis na spɛshal to aplikeshɔn-layk mɛnyu dɛn we de trig akshɔn ɔ fɛnshɔn dɛn. ARIA mɛnyu dɛn kin jɔs gɛt mɛnyu aytem dɛn, chɛkbɔks mɛnyu aytem dɛn, redio bɔtin mɛnyu aytem dɛn, redio bɔtin grup dɛn, ɛn sab-mɛnyu dɛn.
Bootstrap in drɔpdɔwn dɛn, na di ɔda say, dɛn mek am fɔ bi jenɛrik ɛn fɔ yuz fɔ difrɛn sityueshɔn ɛn mak strɔkchɔ dɛn. Fɔ ɛgzampul, i pɔsibul fɔ mek drɔpdɔwn dɛn we gɛt ɔda tin dɛn fɔ put ɛn fɔm kɔntrol dɛn, lɛk say dɛn fɔ fɛn ɔ fɔm dɛn fɔ login. Fɔ dis rizin, Bootstrap nɔ de ɛkspɛkt (nɔ ɔtomɛtik ad) ɛni wan pan di role
ɛn aria-
atribyut dɛn we nid fɔ tru ARIA mɛnyu dɛn. Di wan dɛn we rayt di buk go gɛt fɔ put dɛn mɔ spɛshal atribyut dɛn ya dɛnsɛf.
Bɔt, Bootstrap de ad bilt-in sɔpɔt fɔ mɔs standad kibɔd mɛnyu intarakshɔn dɛn, lɛk di ebul fɔ muv tru wan wan .dropdown-item
ɛlimɛnt dɛn yuz di kɔsa ki dɛn ɛn lɔk di mɛnyu wit di ESCki.
Ɛgzampul dɛn
Rap di drɔpdɔwn in tɔgl (yu bɔtin ɔ link) ɛn di drɔpdɔwn mɛnyu insay .dropdown
, ɔ ɔda ɛlimɛnt we de diklar position: relative;
. Drɔpdɔwn kin trig frɔm <a>
ɔ <button>
ɛlimɛnt fɔ bɛtɛ fit yu pɔtɛnɛshɛl nid dɛm. Di ɛgzampul dɛn we dɛn sho ya de yuz sɛmantik <ul>
ɛlimɛnt dɛn usay i fayn, bɔt dɛn de sɔpɔt kɔstɔm mak.
Wan bɔtin
Ɛni singl .btn
kin tɔn to drɔpdɔwn tɔgl wit sɔm mak chenj dɛn. Na dis na aw yu kin put dɛn fɔ wok wit ɛni wan pan di <button>
ɛlimɛnt dɛn:
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<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>
Ɛn wit <a>
ɛlimɛnt dɛn:
<div class="dropdown">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown link
</a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<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>
Di bes pat na yu kin du dis wit eni button variant, tu:
<!-- 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>
Di bɔtin fɔ split
Semweso, mek split bɔtin drɔpdɔwn dɛn wit klos to di sem mak lɛk wan bɔtin drɔpdɔwn dɛn, bɔt wit di addɛshɔn fɔ .dropdown-toggle-split
fɔ mek dɛn spes fayn fayn wan rawnd di drɔpdɔwn karet.
Wi de yuz dis ekstra klas fɔ ridyus di ɔrizɔntal padding
na ɛni say na di karet bay 25% ɛn pul di margin-left
dat we dɛn ad fɔ rɛgyula bɔtin drɔpdɔwn dɛn. Dɛn ɛkstra chenj dɛn de kin mek di karet de na di sɛnt na di split bɔtin ɛn dɛn kin gi yu wan say fɔ hit we gɛt mɔ saiz nia di men bɔtin.
<!-- 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>
Sayz fɔ di sayz
Bɔtin drɔpdɔwn dɛn de wok wit bɔtin dɛn we gɛt ɔl kayn saiz, ivin di difɔlt ɛn split drɔpdɔwn bɔtin dɛn.
<!-- 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>
Dak drɔp-dɔwn dɛn
Opt insay dak drɔpdɔwn dɛn fɔ mach wan dak navbar ɔ kɔstɔm stayl bay we yu ad .dropdown-menu-dark
pan wan we dɔn de .dropdown-menu
. Nɔ chenj nɔ nid fɔ apin to di tin dɛn we de dɔŋ.
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton2" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="dropdownMenuButton2">
<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>
Ɛn fɔ put am fɔ yuz na 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="#" id="navbarDarkDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="navbarDarkDropdownMenuLink">
<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>
Aw fɔ sho aw fɔ du am
RTL we dɛn kɔl RTL
Dairekshɔn dɛn de mirɔ we yu de yuz Bootstrap na RTL, we min se .dropstart
i go apia na di rayt say.
Drop-ap fɔ de
Trig drɔpdɔwn mɛnyu dɛn ɔp di ɛlimɛnt dɛn bay we yu ad .dropup
to di mama ɛn papa ɛlimɛnt.
<!-- 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>
Drɔprayt
Trig drɔpdɔwn mɛnyu dɛn na di rayt say na di ɛlimɛnt dɛn bay we yu ad .dropend
to di mama ɛn papa ɛlimɛnt.
<!-- Default dropend button -->
<div class="btn-group dropend">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropright
</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 Dropright</span>
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
Drɔplɛft fɔ di wan dɛn we de drɔp
Trig drɔpdɔwn mɛnyu dɛn na di lɛft say na di ɛlimɛnt dɛn bay we yu ad .dropstart
to di mama ɛn papa ɛlimɛnt.
<!-- 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">
<div class="btn-group dropstart" role="group">
<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>
</div>
<button type="button" class="btn btn-secondary">
Split dropstart
</button>
</div>
Di tin dɛn we de na di menyu
Yu kin yuz <a>
ɔ <button>
ɛlimɛnt dɛn as drɔpdɔwn tin dɛn.
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
<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>
Yu kin mek bak tin dɛn we nɔ de intaraktiv drɔpdɔwn wit .dropdown-item-text
. Fil fri fɔ stayl mɔ wit kɔstɔm CSS ɔ tɛks yutiliti dɛn.
<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>
Wok
Ad .active
to tin dɛn we de na di drɔpdɔwn fɔ mek dɛn stayl dɛn as aktif . Fɔ gi di aktiv stet to ɛp tɛnkɔlɔji dɛn, yuz di aria-current
atribyut — yuz di page
valyu fɔ di pej we de naw, ɔ true
fɔ di tin we de naw na wan sɛt.
<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>
Disebul
Ad .disabled
to tin dɛn na di drɔpdɔwn fɔ stayl dɛn as disabled .
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Regular link</a></li>
<li><a class="dropdown-item disabled" href="#" tabindex="-1" aria-disabled="true">Disabled link</a></li>
<li><a class="dropdown-item" href="#">Another link</a></li>
</ul>
Di alaynɛshɔn fɔ di menyu
Bay difɔlt, wan drɔp-dɔwn mɛnyu de ɔtomɛtik wan 100% frɔm di ɔp ɛn along di lɛft say na in mama ɔ papa. Yu kin chenj dis wit di dairekshɔn .drop*
klas dɛn, bɔt yu kin kɔntrol dɛn bak wit ɔda modifya klas dɛn.
Ad .dropdown-menu-end
to a .dropdown-menu
to rayt alaynɛt di drɔpdɔwn mɛnyu. Dairekshɔn dɛn de mirɔ we yu de yuz Bootstrap na RTL, we min se .dropdown-menu-end
i go apia na di lɛft say.
<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>
Alaynɛshɔn we de ansa
If yu want fɔ yuz rispɔnsiv alaynɛshɔn, disable dinamik pozishɔn bay we yu ad di data-bs-display="static"
atribyut ɛn yuz di rispɔnsiv vɛryushɔn klas dɛn.
Fɔ alaynɛt rayt di drɔpdɔwn mɛnyu wit di brekpɔynt we dɛn gi ɔ big wan, ad .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>
Fɔ alaynɛt di lɛft di drɔpdɔwn mɛnyu wit di brekpɔynt we dɛn gi ɔ big wan, ad .dropdown-menu-end
ɛn .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>
Notis se yu nɔ nid fɔ ad data-bs-display="static"
atribyut to drɔpdɔwn bɔtin dɛn na navbar, bikɔs dɛn nɔ de yuz Popper na navbar.
Di opshɔn dɛn fɔ alaynɛt
We yu tek bɔku pan di opshɔn dɛn we dɛn sho ɔp, na wan smɔl kichin sink dɛmo fɔ difrɛn drɔpdɔwn alaynɛshɔn opshɔn dɛn na wan ples.
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<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>
Di tin dɛn we de insay di menyu
Di ed dɛn we de na di ed
Ad wan ɛda fɔ lɛbul sɛkshɔn dɛn fɔ di akshɔn dɛn na ɛni drɔpdɔwn mɛnyu.
<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>
Divayda dɛn
Separet grup dɛn fɔ di tin dɛn we gɛt fɔ du wit di mɛnyu wit wan divayda.
<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>
Tɛks
Put ɛni frifɔm tɛks insay wan drɔpdɔwn mɛnyu wit tɛks ɛn yuz spɛshal yutiliti dɛn . Notis se yu go mɔs nid ɔda stayl dɛn fɔ mek yu nɔ gɛt sayz fɔ mek di meny nɔ big.
<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>
Fɔm dɛn
Put wan fɔm insay wan drɔpdɔwn mɛnyu, ɔ mek am insay wan drɔpdɔwn mɛnyu, ɛn yuz margin ɔ padding utilities fɔ gi am di negatif spes we yu nid.
<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>
<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>
Di tin dɛn we yu kin pik fɔ drɔp
Yuz data-bs-offset
ɔ data-bs-reference
fɔ chenj di say we di drɔp-dɔwn de.
<div class="d-flex">
<div class="dropdown me-1">
<button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuOffset" data-bs-toggle="dropdown" aria-expanded="false" data-bs-offset="10,20">
Offset
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuOffset">
<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" id="dropdownMenuReference" data-bs-toggle="dropdown" aria-expanded="false" data-bs-reference="parent">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuReference">
<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>
Auto klos bihayvya
Bay difɔlt, di drɔpdɔwn mɛnyu kin lɔk we yu klik insay ɔ ausayd di drɔpdɔwn mɛnyu. Yu kin yuz di autoClose
opshɔn fɔ chenj dis bihayvya na di drɔp-dɔwn.
<div class="btn-group">
<button class="btn btn-secondary dropdown-toggle" type="button" id="defaultDropdown" data-bs-toggle="dropdown" data-bs-auto-close="true" aria-expanded="false">
Default dropdown
</button>
<ul class="dropdown-menu" aria-labelledby="defaultDropdown">
<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" id="dropdownMenuClickableOutside" data-bs-toggle="dropdown" data-bs-auto-close="inside" aria-expanded="false">
Clickable outside
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuClickableOutside">
<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" id="dropdownMenuClickableInside" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false">
Clickable inside
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuClickableInside">
<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" id="dropdownMenuClickable" data-bs-toggle="dropdown" data-bs-auto-close="false" aria-expanded="false">
Manual close
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuClickable">
<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>
Sass we bin de
Di tin dɛn we kin chenj
Variables fɔ ɔl di drɔpdɔwn dɛn:
$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: rgba($black, .15);
$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($gray-900, 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: $dropdown-padding-y $dropdown-item-padding-x;
Variables fɔ di dak drɔpdɔwn : .
$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;
Variables fɔ di CSS-based carets we de sho wan drɔpdɔwn in intaraktiviti:
$caret-width: .3em;
$caret-vertical-align: $caret-width * .85;
$caret-spacing: $caret-width * .85;
Mixin dɛn
Dɛn kin yuz miksin fɔ mek di CSS-based carets ɛn dɛn kin fɛn am na 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;
}
}
}
Aw fɔ yuz am
Via data atribyut ɔ JavaSkript, di drɔpdɔwn plɔgin de chenj di tin dɛn we dɛn ayd (drɔpdɔwn mɛnyu dɛn) bay we i de chenj di .show
klas na di mama ɔ papa .dropdown-menu
. Dɛn data-bs-toggle="dropdown"
kin abop pan di atribyut fɔ lɔk drɔpdɔwn mɛnyu dɛn na wan aplikeshɔn lɛvɛl, so i fayn fɔ yuz am ɔltɛm.
mouseover
handla dɛn to di pikin dɛn we de nia di
<body>
ɛlimɛnt. Dis admittedly ugly hack na nid fɔ wok arawnd wan
quirk in iOS’ event delegation , we ɔda we go mek wan tap ɛnisay ausayd di drɔpdɔwn nɔ trig di kɔd we de lɔk di drɔpdɔwn. We dɛn dɔn lɔk di drɔp-dɔwn, dɛn kin pul dɛn ɔda ɛmti
mouseover
handla dɛn ya.
Via data atribyut dɛn
Ad data-bs-toggle="dropdown"
to link ɔ bɔtin fɔ chenj wan drɔp-dɔwn.
<div class="dropdown">
<button id="dLabel" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown trigger
</button>
<ul class="dropdown-menu" aria-labelledby="dLabel">
...
</ul>
</div>
Yu kin yuz JavaSkript fɔ yuz am
Kɔl di drɔpdɔwn dɛn bay JavaSkript:
var dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'))
var dropdownList = dropdownElementList.map(function (dropdownToggleEl) {
return new bootstrap.Dropdown(dropdownToggleEl)
})
data-bs-toggle="dropdown"
stil nid fɔ de
I nɔ mata if yu kɔl yu drɔpdɔwn bay JavaSkript ɔ insted yu yuz di data-api, data-bs-toggle="dropdown"
i nid fɔ de ɔltɛm na di drɔpdɔwn in trig ɛlimɛnt.
Di tin dɛn we yu kin pik fɔ du
Yu kin pas opshɔn dɛn bay we yu yuz data atribyut ɔ JavaSkript. Fɔ data atribyut dɛn, ad di opshɔn nem to data-bs-
, lɛk insay data-bs-offset=""
. Mek shɔ se yu chenj di kes tayp fɔ di opshɔn nem frɔm camelCase to kebab-case we yu de pas di opshɔn dɛn via data atribyut dɛn. Fɔ ɛgzampul, bifo yu yuz data-bs-autoClose="false"
, yuz data-bs-auto-close="false"
.
Nem | Kayn | Balans | Tɔk bɔt |
---|---|---|---|
boundary |
string fɔ di wan dɛn we de | tin | 'clippingParents' |
Ovaflɔ kɔnstrakshɔn bɔda fɔ di drɔpdɔwn mɛnyu (i de aplay nɔmɔ to Popper in preventOverflow modifya). Bay difɔlt na 'clippingParents' ɛn kin aksept wan HTMLElement rɛfrɛns (via JavaSkript nɔmɔ). Fɔ no mɔ, luk na Popper’s detectOverflow docs . |
reference |
string fɔ di wan dɛn we de | elemɛnt | tin | 'toggle' |
Rifrɛns ɛlimɛnt na di drɔpdɔwn mɛnyu. Aksept di valyu dɛn fɔ 'toggle' , 'parent' , wan HTMLElement rɛfrɛns ɔ wan ɔbjɛkt we de gi getBoundingClientRect . Fɔ no mɔ rif to Popper in kɔnstrɔkta dɔk ɛn vayrɔyal ɛlimɛnt dɔk . |
display |
rop | 'dynamic' |
Bay difɔlt, wi de yuz Popper fɔ dinamik pozishɔn. Disable dis wit static . |
offset |
arenjmɛnt fɔ | string fɔ di wan dɛn we de | wok | [0, 2] |
Ɔfset fɔ di drɔpdɔwn rilitiv to in target. Yu kin pas wan string insay data atribyut dɛn wit kɔma separet valyu dɛn lɛk: We dɛn yuz wan fɛnshɔn fɔ no di ɔfset, dɛn kin kɔl am wit wan ɔbjɛkt we gɛt di pɔpa plesmɛnt, di rɛfrɛns, ɛn di pɔpa rɛkt dɛn as in fɔs argumɛnt. Di trigεrin εlimεnt DOM node de pas as di sɛkɔn argumɛnt. Di fɛnshɔn fɔ ritɔn wan arenjmɛnt wit tu nɔmba dɛn: . Fɔ no mɔ, luk na Popper’s offset docs . |
autoClose |
boolean we de na di wɔl | rop | true |
Kɔnfigyut di ɔto klos bihayvya fɔ di drɔpdɔwn:
|
popperConfig |
nul we de na di wɔl | ɔbjɛkt | wok | null |
Fɔ chenj Bootstrap in difɔlt Popper kɔnfigyushɔn, si Popper in kɔnfigyushɔn . We dɛn yuz wan fɛnshɔn fɔ mek di Popper kɔnfigyushɔn, dɛn kin kɔl am wit wan ɔbjɛkt we gɛt di Bootstrap in difɔlt Popper kɔnfigyushɔn. I de ɛp yu fɔ yuz ɛn jɔyn di difɔlt wit yu yon kɔnfigyushɔn. Di fɛnshɔn fɔ ritɔn wan kɔnfigyushɔn ɔbjɛkt fɔ Popa. |
Yuz funkshɔn witpopperConfig
var dropdown = new bootstrap.Dropdown(element, {
popperConfig: function (defaultBsPopperConfig) {
// var newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Di we aw dɛn de du am
We | Tɔk bɔt |
---|---|
toggle |
Tɔgl di drɔpdɔwn mɛnyu fɔ wan givɛn navbar ɔ tab nevigishɔn. |
show |
Sho di drɔpdɔwn mɛnyu fɔ wan givɛn navbar ɔ tab nevigishɔn. |
hide |
Ayd di drɔpdɔwn mɛnyu fɔ wan givɛn navbar ɔ tab nevigishɔn. |
update |
Ɔpdet di pozishɔn fɔ wan ɛlimɛnt in drɔpdɔwn. |
dispose |
Destroy wan element in drɔpdɔwn. (I de pul di data we dɛn dɔn kip na di DOM ɛlimɛnt) |
getInstance |
Statik we de alaw yu fɔ gɛt di drɔpdɔwn instans we gɛt fɔ du wit wan DOM ɛlimɛnt, yu kin yuz am lɛk dis:bootstrap.Dropdown.getInstance(element) |
getOrCreateInstance |
Statik mɛtɔd we de ritɔn wan drɔpdɔwn instans we gɛt fɔ du wit wan DOM ɛlimɛnt ɔ mek wan nyu wan insay kes we dɛn nɔ bin initialize am. Yu kin yuz am lɛk dis:bootstrap.Dropdown.getOrCreateInstance(element) |
Di tin dɛn we kin apin
Ɔl di drɔpdɔwn ivin dɛn de faya pan di toggling ɛlimɛnt ɛn afta dat dɛn de bɔbul ɔp. So yu kin ad ivin lisin dɛn bak pan di .dropdown-menu
's mama ɛn papa ɛlimɛnt. hide.bs.dropdown
ɛn hidden.bs.dropdown
ivin dɛn gɛt clickEvent
prɔpati (onli we di ɔrijinal Ivint tayp na click
) we gɛt wan Ivint Ɔbjɛkt fɔ di klik ivin.
We | Tɔk bɔt |
---|---|
show.bs.dropdown |
Faya wantɛm wantɛm we dɛn kɔl di sho instans mɛtɔd. |
shown.bs.dropdown |
Faya we dɛn dɔn mek di drɔpdɔwn si di pɔsin we de yuz am ɛn di CSS transishɔn dɛn dɔn dɔn. |
hide.bs.dropdown |
Faya wantɛm wantɛm we dɛn dɔn kɔl di ayd instans mɛtɔd. |
hidden.bs.dropdown |
Faya we di drɔpdɔwn dɔn dɔn fɔ ayd frɔm di yuza ɛn CSS transishɔn dɛn dɔn dɔn. |
var myDropdown = document.getElementById('myDropdown')
myDropdown.addEventListener('show.bs.dropdown', function () {
// do something...
})