Skip to di men tin dɛn we de insay Skip to doks nevigishɔn
Check
in English

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.jswe 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 .btnkin 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:

html
<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>

Ɛn wit <a>ɛlimɛnt dɛn:

html
<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>

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-splitfɔ mek dɛn spes fayn fayn wan rawnd di drɔpdɔwn karet.

Wi de yuz dis ekstra klas fɔ ridyus di ɔrizɔntal paddingna ɛni say na di karet bay 25% ɛn pul di margin-leftdat 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-darkpan wan we dɔn de .dropdown-menu. Nɔ chenj nɔ nid fɔ apin to di tin dɛn we de dɔŋ.

html
<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>

Ɛn fɔ put am fɔ yuz na navbar:

html
<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>

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 .dropstarti go apia na di rayt say.

Na di sɛnt

Mek di drɔpdɔwn mɛnyu sɛntrɛd dɔŋ di tɔgl wit .dropdown-centerpan di mama ɛn papa ɛlimɛnt.

html
<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>

Drop-ap fɔ de

Trig drɔpdɔwn mɛnyu dɛn ɔp di ɛlimɛnt dɛn bay we yu ad .dropupto 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>

Dropup we de na di sɛnt

Mek di drɔp mɛnyu sɛnt ɔp di tɔgl wit .dropup-centerpan di mama ɛn papa ɛlimɛnt.

html
<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>

Drɔpɛnd fɔ go

Trig drɔpdɔwn mɛnyu dɛn na di rayt say na di ɛlimɛnt dɛn bay we yu ad .dropendto 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">
    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>

Drɔpstart fɔ du dat

Trig drɔpdɔwn mɛnyu dɛn na di lɛft say na di ɛlimɛnt dɛn bay we yu ad .dropstartto 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 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>

Yu kin yuz <a>ɔ <button>ɛlimɛnt dɛn as drɔpdɔwn tin dɛn.

html
<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>

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.

html
<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 .activeto 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-currentatribyut — yuz di pagevalyu fɔ di pej we de naw, ɔ truefɔ di tin we de naw na wan sɛt.

html
<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 .disabledto tin dɛn na di drɔpdɔwn fɔ stayl dɛn as disabled .

html
<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>

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-endto a .dropdown-menuto 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-endi go apia na di lɛft say.

Hed dɛn de ɔp! Drɔpdɔwn dɛn de pozishɔn tank to Popper pas we dɛn de insay wan navbar.
html
<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.

html
<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.

html
<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.

html
<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>

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.

html
<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.

html
<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.

html
<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.

html
<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>
html
<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>

Yuz data-bs-offsetɔ data-bs-referencefɔ chenj di say we di drɔp-dɔwn de.

html
<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>

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 autoCloseopshɔn fɔ chenj dis bihayvya na di drɔp-dɔwn.

html
<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 we dɛn kɔl CSS

Di tin dɛn we kin chenj

Dɛn ad am na v5.2.0

As pat pan Bootstrap in evolvin CSS vɛriɔbul dɛn aprɔch, drɔpdɔwn dɛn naw de yuz lokal CSS vɛriɔbul dɛn on .dropdown-menufɔ ɛnhans rial-taym kɔstɔmayshɔn. Valyu fɔ di CSS vɛriɔbul dɛn de sɛt via Sass, so Sass kɔstɔmayshɔn stil de sɔpɔt, bak.

  --#{$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};
  

Yu kin si kɔstɔmayshɔn tru CSS vɛriɔbul dɛn na di .dropdown-menu-darkklas usay wi de ɔvalayz spɛshal valyu dɛn we wi nɔ ad dupliket CSS sɛlɛktɔ dɛn.

  --#{$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};
  

Sass di vayriɔbul dɛn

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:             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

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 .showklas 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.

Na divays dɛn we gɛt tɔch-ɛnibɛl, we yu opin wan drɔpdɔwn, i de ad ɛmti mouseoverhandla 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 mouseoverhandla 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 type="button" data-bs-toggle="dropdown" aria-expanded="false">
    Dropdown trigger
  </button>
  <ul class="dropdown-menu">
    ...
  </ul>
</div>

Yu kin yuz JavaSkript fɔ yuz am

Kɔl di drɔpdɔwn dɛn bay JavaSkript:

const dropdownElementList = document.querySelectorAll('.dropdown-toggle')
const dropdownList = [...dropdownElementList].map(dropdownToggleEl => 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

As opshɔn dɛn kin pas bay data atribyut ɔ JavaSkript, yu kin ad opshɔn nem to data-bs-, lɛk insay data-bs-animation="{value}". 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 tru data atribyut dɛn. Fɔ ɛgzampul, yuz data-bs-custom-class="beautifier"insted fɔ data-bs-customClass="beautifier".

As fɔ Bootstrap 5.2.0, ɔl di kɔmpɔnɛnt dɛn de sɔpɔt wan ɛkspirimɛnt rizɔv data atribyut data-bs-configwe kin os simpul kɔmpɔnɛnt kɔnfigyushɔn as JSON string. We wan ɛlimɛnt gɛt data-bs-config='{"delay":0, "title":123}'ɛn data-bs-title="456"atribyut, di fayn titlevalyu go bi 456ɛn di sɛpret data atribyut dɛn go ɔvalayz valyu dɛn we dɛn gi pan data-bs-config. Apat frɔm dat, di data atribyut dɛn we de naw ebul fɔ gɛt JSON valyu dɛn lɛk data-bs-delay='{"show":0,"hide":150}'.

Nem Kayn Balans Tɔk bɔt
autoClose boolean, we dɛn kin yuz fɔ strɛch true Kɔnfigyut di ɔto klos bihayvya fɔ di drɔpdɔwn:
  • true- di drɔpdɔwn go lɔk bay we yu klik na do ɔ insay di drɔpdɔwn mɛnyu.
  • false- di drɔpdɔwn go lɔk bay we yu klik di tɔgl bɔtin ɛn kɔl hideɔ togglemɛtɔd wit yu an. (Asso dɛn nɔ go lɔk am bay we yu prɛs escdi ki)
  • 'inside'- di drɔpdɔwn go lɔk (onli) bay we yu klik insay di drɔpdɔwn mɛnyu.
  • 'outside'- di drɔpdɔwn go lɔk (onli) bay we yu klik ɔdasay na di drɔpdɔwn mɛnyu.
Notis: di drɔpdɔwn kin ɔltɛm lɔk wit di ESCki.
boundary string, ɛlimɛnt '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 .
display rop 'dynamic' Bay difɔlt, wi de yuz Popper fɔ dinamik pozishɔn. Disable dis wit static.
offset arenjmɛnt, string, fɛnshɔn [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: data-bs-offset="10,20". 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: skidding , distans . Fɔ no mɔ, luk na Popper’s offset docs .
popperConfig nul, ɔbjɛkt, fɛnshɔn 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.
reference string, ɛlimɛnt, ɔbjɛkt '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 .

Yuz funkshɔn witpopperConfig

const dropdown = new bootstrap.Dropdown(element, {
  popperConfig(defaultBsPopperConfig) {
    // const newPopperConfig = {...}
    // use defaultBsPopperConfig if needed...
    // return newPopperConfig
  }
})

Di we aw dɛn de du am

We Tɔk bɔt
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 i nɔ bin initialize. Yu kin yuz am lɛk dis: bootstrap.Dropdown.getOrCreateInstance(element).
hide Ayd 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.
toggle Tɔgl 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.

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.dropdownivin dɛn gɛt clickEventprɔpati (onli we di ɔrijinal Ivint tayp na click) we gɛt wan Ivint Ɔbjɛkt fɔ di klik ivin.

Di kayn tin we apin Tɔk bɔt
hide.bs.dropdown Faya wantɛm wantɛm we hidedɛn dɔn kɔl di 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.
show.bs.dropdown Faya wantɛm wantɛm we dɛn kɔl di showinstans 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.
const myDropdown = document.getElementById('myDropdown')
myDropdown.addEventListener('show.bs.dropdown', event => {
  // do something...
})