Pitani kuzinthu zazikulu Pitani kumayendedwe adocs
in English

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.jsyomwe 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 rolemwazofunikira 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-itemzilizonse 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 .btnchikhoza 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" 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>

Ndipo ndi <a>zinthu:

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

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-splitmalo oyenera kuzungulira malo otsikira.

Timagwiritsa ntchito kalasi yowonjezerayi kuti tichepetse zopingasa paddingmbali zonse za chisamaliro ndi 25% ndikuchotsa margin-leftzomwe 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-darkpa .dropdown-menu. Palibe zosintha zomwe zimafunikira pazotsitsa.

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

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="#" 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>

Mayendedwe

RTL

Mayendedwe amawonetsedwa mukamagwiritsa ntchito Bootstrap mu RTL, kutanthauza .dropstartkuti kudzawoneka kumanja.

Kusiya

Yambitsani mindandanda yotsikira pamwamba pa zinthu powonjezera .dropupku 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>

Dropright

Yambitsani mindandanda yotsikira kumanja kwa zinthu powonjezera .dropendku 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">
    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>

Dropleft

Yambitsani mindandanda yotsikira kumanzere kwa zinthu powonjezera .dropstartku 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">
  <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>

Mutha kugwiritsa ntchito zinthu <a>kapena <button>zinthu ngati zotsitsa.

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

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 .activekuzinthu zomwe zili m'munsi kuti ziwoneke ngati zikugwira ntchito . Kuti mufotokozere zomwe zikuchitika ku matekinoloje othandizira, gwiritsani ntchito aria-currentchidziwitsocho - pogwiritsa ntchito pagemtengo watsamba lomwe lili pano, kapena zomwe truezili 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 .disabledkuzinthu 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" href="#" tabindex="-1" aria-disabled="true">Disabled link</a></li>
  <li><a class="dropdown-item" href="#">Another link</a></li>
</ul>

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-endku a .dropdown-menukulumikiza kumanja menyu yotsitsa. Mayendedwe amawonetsedwa mukamagwiritsa ntchito Bootstrap mu RTL, kutanthauza .dropdown-menu-endkuti kudzawonekera kumanzere.

Mungodziwiratu! Zotsitsa zimayikidwa chifukwa cha Popper pokhapokha ngati zili mu navbar.
<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-endndi .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" 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>

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

Gwiritsani ntchito data-bs-offsetkapena data-bs-referencekusintha malo otsitsa.

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

Khalidwe lotseka basi

Mwachikhazikitso, menyu yotsitsa imatsekedwa mukadina mkati kapena kunja kwa menyu yotsitsa. Mutha kugwiritsa ntchito autoClosemwayiwu kuti musinthe machitidwe otsitsa.

<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

Zosintha

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

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 .showkalasi pa kholo .dropdown-menu. Lingaliroli data-bs-toggle="dropdown"limadaliridwa potseka mindandanda yazakudya pamlingo wogwiritsa ntchito, ndiye ndibwino kuti muzigwiritsa ntchito nthawi zonse.

Pazida zothandizidwa ndi kukhudza, kutsegula kutsika kumawonjezera zida zopanda kanthu mouseoverkwa 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 mouseoverizi zimachotsedwa.

Kudzera muzochita za data

Onjezani data-bs-toggle="dropdown"ku ulalo kapena batani kuti musinthe kutsitsa.

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

Kudzera pa JavaScript

Imbani zotsitsa kudzera pa JavaScript:

var dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'))
var dropdownList = dropdownElementList.map(function (dropdownToggleEl) {
  return 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

Zosankha zitha kuperekedwa kudzera pa data kapena JavaScript. Pamawonekedwe a data, yonjezerani dzina lachisankho ku data-bs-, monga mu data-bs-offset="". Onetsetsani kuti musinthe mtundu wamtundu wa zosankha kuchokera ku camelCase kupita ku kebab-case podutsa zosankha kudzera pa data. Mwachitsanzo, m'malo mogwiritsa data-bs-autoClose="false"ntchito data-bs-auto-close="false".

Dzina Mtundu Zosasintha Kufotokozera
boundary chingwe | chinthu '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 .
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 .
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 zomwe zili 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, distance]

Kuti mumve zambiri onani za Popper's offset docs .

autoClose boole | chingwe true

Konzani machitidwe otsekera otsikirapo:

  • true- kutsitsa kudzatsekedwa ndikudina kunja kapena mkati mwa menyu otsitsa.
  • false- kutsitsa kudzatsekedwa podina batani losintha ndikuyimbira pamanja hidekapena togglenjira. (Nazonso sizitsekedwa ndi kukanikiza esckiyi)
  • 'inside'- kutsitsa kudzatsekedwa (kokha) ndikudina mkati mwa menyu otsitsa.
  • 'outside'- kutsitsa kudzatsekedwa (kokha) podina kunja kwa menyu yotsitsa.
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.

Kugwiritsa ntchito ndipopperConfig

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

Njira

Njira Kufotokozera
toggle Imatembenuza menyu yotsikira ya navbar yopatsidwa kapena kusakatula kwa tabu.
show Imawonetsa menyu otsikira a navbar yopatsidwa kapena navigation ya tabbed.
hide Imabisa menyu yotsikira ya navbar yoperekedwa kapena kusakatula kwa tabu.
update Imawonjezera pomwe pali kutsika kwa chinthu.
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)

Zochitika

Zochitika zonse zotsitsa zimawomberedwa pa toggling element kenako ndikuwomberedwa. Kotero inu mukhoza kuwonjezera omvera zochitika pa .dropdown-menu's kholo element. hide.bs.dropdownndipo hidden.bs.dropdownzochitika zimakhala ndi clickEventkatundu (pokhapo pamene mtundu wa Chochitika choyambirira uli click) chomwe chili ndi Chochitika Chochitika cha chochitikacho.

Njira Kufotokozera
show.bs.dropdown Kuwotcha nthawi yomweyo njira yachiwonetsero imatchedwa.
shown.bs.dropdown Kuwotchedwa pamene dontho lakhala likuwonekera kwa wogwiritsa ntchito ndipo kusintha kwa CSS kwatha.
hide.bs.dropdown Kuwotcha nthawi yomweyo njira yobisala itayitanidwa.
hidden.bs.dropdown Kuthamangitsidwa pamene dontho latha kubisidwa kwa wogwiritsa ntchito ndipo kusintha kwa CSS kwatha.
var myDropdown = document.getElementById('myDropdown')
myDropdown.addEventListener('show.bs.dropdown', function () {
  // do something...
})