Source

Mabatani

Gwiritsani ntchito masitayelo a Bootstrap pamabatani pazochita m'mawonekedwe, zokambirana, ndi zina zambiri mothandizidwa ndi makulidwe angapo, zigawo, ndi zina zambiri.

Zitsanzo

Bootstrap imaphatikizapo masitayelo angapo ofotokozedweratu, iliyonse imagwira ntchito yakeyake, ndi zina zowonjezera zomwe zimaponyedwa kuti ziziwongolera.

<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-dark">Dark</button>

<button type="button" class="btn btn-link">Link</button>
Kupereka tanthauzo ku matekinoloje othandizira

Kugwiritsa ntchito utoto kuti muwonjezere tanthauzo kumangopereka chithunzithunzi, chomwe sichidzaperekedwa kwa ogwiritsa ntchito matekinoloje othandizira - monga owerenga pazenera. Onetsetsani kuti zomwe zatchulidwa ndi mtunduwo zikuwonekera kuchokera pazomwe zili (monga zolemba zowonekera), kapena zikuphatikizidwa ndi njira zina, monga zolemba zina zobisika ndi .sr-onlykalasi.

Letsani kukulunga mawu

Ngati simukufuna kuti mawu a batani atseke, mutha kuwonjezera .text-nowrapkalasi ku batani. Ku Sass, mutha $btn-white-space: nowrapkuyimitsa kutseka kwa mawu pa batani lililonse.

Ma tag a batani

Maphunzirowa .btnamapangidwa kuti agwiritsidwe ntchito ndi <button>element. Komabe, mutha kugwiritsanso ntchito makalasi awa <a>kapena <input>zinthu (ngakhale asakatuli ena atha kugwiritsa ntchito kumasulira kosiyana pang'ono).

Mukamagwiritsa ntchito mabatani azinthu <a>zomwe zimagwiritsidwa ntchito kuyambitsa ntchito zapatsamba (monga kugwa), m'malo molumikizana ndi masamba atsopano kapena magawo omwe ali patsamba lapano, maulalo awa ayenera kuperekedwa role="button"kuti afotokozere moyenera cholinga chawo kuukadaulo wothandizira monga. owerenga chophimba.

Lumikizani
<a class="btn btn-primary" href="#" role="button">Link</a>
<button class="btn btn-primary" type="submit">Button</button>
<input class="btn btn-primary" type="button" value="Input">
<input class="btn btn-primary" type="submit" value="Submit">
<input class="btn btn-primary" type="reset" value="Reset">

Mabatani owonetsera

Mukufuna batani, koma osati mitundu yayikulu yakumbuyo yomwe amabweretsa? Bwezerani m'malo mwa makalasi osintha .btn-outline-*kuti muchotse zithunzi zonse zakumbuyo ndi mitundu pa batani lililonse.

<button type="button" class="btn btn-outline-primary">Primary</button>
<button type="button" class="btn btn-outline-secondary">Secondary</button>
<button type="button" class="btn btn-outline-success">Success</button>
<button type="button" class="btn btn-outline-danger">Danger</button>
<button type="button" class="btn btn-outline-warning">Warning</button>
<button type="button" class="btn btn-outline-info">Info</button>
<button type="button" class="btn btn-outline-light">Light</button>
<button type="button" class="btn btn-outline-dark">Dark</button>

Makulidwe

Mukufuna mabatani akulu kapena ang'onoang'ono? Onjezani .btn-lgkapena .btn-smma size owonjezera.

<button type="button" class="btn btn-primary btn-lg">Large button</button>
<button type="button" class="btn btn-secondary btn-lg">Large button</button>
<button type="button" class="btn btn-primary btn-sm">Small button</button>
<button type="button" class="btn btn-secondary btn-sm">Small button</button>

Pangani mabatani a block level—omwe amatambasula m'lifupi mwa kholo lonse—powonjezera .btn-block.

<button type="button" class="btn btn-primary btn-lg btn-block">Block level button</button>
<button type="button" class="btn btn-secondary btn-lg btn-block">Block level button</button>

Dziko logwira ntchito

Mabatani adzawoneka atapanikizidwa (ndi maziko akuda, malire akuda, ndi mthunzi wamkati) akamagwira ntchito. Palibe chifukwa chowonjezera kalasi ku <button>s pomwe amagwiritsa ntchito kalasi yabodza . Komabe, mutha kukakamizabe mawonekedwe omwewo .active(ndikuphatikizanso aria-pressed="true") ngati mungafunikire kubwereza boma mwadongosolo.

<a href="#" class="btn btn-primary btn-lg active" role="button" aria-pressed="true">Primary link</a>
<a href="#" class="btn btn-secondary btn-lg active" role="button" aria-pressed="true">Link</a>

Dziko olumala

Pangani mabatani kuti awoneke ngati osagwira ntchito powonjezera mawonekedwe a disabledboolean ku <button>chinthu chilichonse.

<button type="button" class="btn btn-lg btn-primary" disabled>Primary button</button>
<button type="button" class="btn btn-secondary btn-lg" disabled>Button</button>

Mabatani olemala omwe amagwiritsa ntchito <a>chinthucho amachita mosiyana pang'ono:

  • <a>s sizigwirizana ndi disabledchikhalidwecho, chifukwa chake muyenera kuwonjezera .disabledkalasi kuti iwoneke ngati yolumala.
  • Masitayelo ena ogwirizana ndi mtsogolo akuphatikizidwa kuti muyimitse zonse pamabatani pointer-eventsa nangula. M'masakatuli omwe amathandizira katunduyo, simudzawona cholozera choyimitsidwa konse.
  • Mabatani olemala akuyenera kukhala ndi mawonekedwe aria-disabled="true"owonetsa momwe zinthu zilili kuukadaulo wothandizira.
<a href="#" class="btn btn-primary btn-lg disabled" tabindex="-1" role="button" aria-disabled="true">Primary link</a>
<a href="#" class="btn btn-secondary btn-lg disabled" tabindex="-1" role="button" aria-disabled="true">Link</a>

Kalasiyo .disabledimagwiritsa ntchito pointer-events: nonekuyesa kuletsa magwiridwe antchito a <a>s, koma katundu wa CSS sunakhazikitsidwebe. Kuphatikiza apo, ngakhale m'masakatuli omwe amathandizira pointer-events: none, kuyenda kwa kiyibodi sikukhudzidwa, kutanthauza kuti ogwiritsa ntchito kiyibodi omwe amawona komanso ogwiritsa ntchito matekinoloje othandizira azitha kuyatsa maulalo awa. Chifukwa chake kuti mukhale otetezeka, onjezani zomwe tabindex="-1"zili pamalumikizidwe awa (kuti muwaletse kuti asalandire chidwi cha kiyibodi) ndikugwiritsa ntchito JavaScript kuti mulepheretse magwiridwe ake.

batani plugin

Chitani zambiri ndi mabatani. Batani lowongolera likunena kapena pangani magulu a mabatani azinthu zambiri ngati zida.

Sinthani maiko

Onjezani data-toggle="button"kuti musinthe mawonekedwe a batani active. Ngati musinthiratu batani, muyenera kuwonjezera pamanja .activekalasi ndi aria-pressed="true" ku <button>.

<button type="button" class="btn btn-primary" data-toggle="button" aria-pressed="false">
  Single toggle
</button>

Chongani ndi mabatani wailesi

Masitayilo a Bootstrap .buttonatha kugwiritsidwa ntchito pazinthu zina, monga <label>s, kuti apereke bokosi loyang'ana kapena mabatani a wayilesi. Onjezani data-toggle="buttons"ku .btn-groupzomwe zili ndi mabatani osinthidwawo kuti athe kusintha machitidwe awo kudzera pa JavaScript ndikuwonjezera .btn-group-togglemasitayilo omwe <input>ali mkati mwa mabatani anu. Zindikirani kuti mutha kupanga mabatani olowetsa mphamvu imodzi kapena magulu awo.

Mawonekedwe osankhidwa a mabataniwa amangosinthidwa ndi chochitika clickchomwe chili pa batani. Ngati mugwiritsa ntchito njira ina yosinthira zomwe mwalowetsamo, mwachitsanzo, pogwiritsa <input type="reset">ntchito kapena kugwiritsa ntchito pamanja zomwe checkedmwalowetsamo, muyenera kusintha .activepamanja <label>.

Zindikirani kuti mabatani omwe adasankhidwa kale amafuna kuti muwonjezere .activekalasi pa zolowetsa <label>.

<div class="btn-group-toggle" data-toggle="buttons">
  <label class="btn btn-secondary active">
    <input type="checkbox" checked> Checked
  </label>
</div>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
  <label class="btn btn-secondary active">
    <input type="radio" name="options" id="option1" checked> Active
  </label>
  <label class="btn btn-secondary">
    <input type="radio" name="options" id="option2"> Radio
  </label>
  <label class="btn btn-secondary">
    <input type="radio" name="options" id="option3"> Radio
  </label>
</div>

Njira

Njira Kufotokozera
$().button('toggle') Imatembenuza dziko lokankhira. Imawonetsa batani kuwonekera kuti yayatsidwa.
$().button('dispose') Iwononga batani la chinthu.