Source

Izinkinobho

Sebenzisa izitayela zenkinobho yangokwezifiso ye-Bootstrap ngezenzo ngamafomu, izingxoxo, nokuningi ngosekelo losayizi abaningi, izifunda, nokuningi.

Izibonelo

I-Bootstrap ifaka phakathi izitayela zezinkinobho ezichazwe ngaphambilini, ngasinye sisebenzisa inhloso yaso ye-semantic, kanye nokwengeziwe okumbalwa okuphonswe ukuze kulawulwe okwengeziwe.

<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>
Ukudlulisa incazelo kubuchwepheshe obusizayo

Ukusebenzisa umbala ukwengeza incazelo kunikeza kuphela inkomba ebonakalayo, engeke idluliselwe kubasebenzisi bobuchwepheshe obusizayo - njengezifundi zesikrini. Qinisekisa ukuthi ulwazi olushiwo umbala lusobala kokuqukethwe ngokwako (isb umbhalo obonakalayo), noma lufakwe ngezinye izindlela, njengombhalo owengeziwe ofihliwe .sr-onlynekilasi.

Omaka bezinkinobho

Amakilasi .btnaklanyelwe ukusetshenziswa ne- <button>elementi. Kodwa-ke, ungasebenzisa la makilasi kuwo <a>noma <input>izakhi (yize ezinye iziphequluli zingasebenzisa ukunikezwa okuhlukile kancane).

Uma usebenzisa izinkinobho zamakilasi kuma- <a>elementi asetshenziselwa ukuqalisa ukusebenza kwekhasi (njengokuqukethwe okugoqiwe), esikhundleni sokuxhuma emakhasini amasha noma izigaba ezingaphakathi kwekhasi lamanje, lezi zixhumanisi kufanele zinikezwe role="button"ukuze zidlulisele injongo yazo ngendlela efanele kubuchwepheshe obusizayo obufana no. izifundi zesikrini.

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

Izinkinobho zohlaka

Udinga inkinobho, kodwa hhayi imibala yangemuva enzima abayilethayo? Miselela amakilasi okulungisa azenzakalelayo .btn-outline-*nalawo ukuze ususe zonke izithombe ezingemuva nemibala kunoma iyiphi inkinobho.

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

Osayizi

Uyathanda izinkinobho ezinkulu noma ezincane? Engeza .btn-lgnoma .btn-smosayizi abengeziwe.

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

Dala izinkinobho zeleveli yebhulokhi—lezo ezinobubanzi obugcwele bomzali—ngokwengeza .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>

Isimo esisebenzayo

Izinkinobho zizovela zicindezelwe (ezinengemuva elimnyama, umngcele omnyama, nesithunzi esifakiwe) uma isebenza. Asikho isidingo sokwengeza iklasi ku- <button>s njengoba zisebenzisa i-pseudo-class . Nokho, usengaphoqa ukubonakala okufanayo okusebenzayo nge .active(futhi ufake aria-pressed="true"isibaluli) uma udinga ukuphindaphinda isimo ngokohlelo.

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

Isimo sokukhubazeka

Yenza izinkinobho zibukeke zingasebenzi ngokwengeza disabledisibaluli se-boolean kunoma iyiphi i- <button>elementi.

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

Izinkinobho ezikhutshaziwe ezisebenzisa i- <a>elementi ziziphatha ngendlela ehlukile:

  • <a>s azisekeli disabledisibaluli, ngakho-ke kufanele wengeze .disabledikilasi ukuze ulenze libonakale likhubazekile.
  • Ezinye izitayela ezilungele ikusasa zifakiwe ukuze kukhubazwe konke pointer-eventskuzinkinobho zehange. Kuziphequluli ezisekela leso sakhiwo, ngeke usibone nakancane ikhesa ekhutshaziwe.
  • Izinkinobho ezikhutshaziwe kufanele zifake aria-disabled="true"isibaluli ukuze zibonise isimo se-elementi kubuchwepheshe obusizayo.
<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>

Ikilasi .disabledlisebenzisa pointer-events: noneukuzama ukukhubaza ukusebenza kwesixhumanisi kwe- <a>s, kodwa leyo mpahla ye-CSS ayikakamiswanga. Ngaphezu kwalokho, ngisho nasezipheqululini ezisekelayo pointer-events: none, ukuzulazula kwekhibhodi kuhlala kungathinteki, okusho ukuthi abasebenzisi bekhibhodi ababonayo nabasebenzisi bobuchwepheshe obusizayo basazokwazi ukwenza lezi zixhumanisi zisebenze. Ukuze uphephe, engeza tabindex="-1"isibaluli kulezi zixhumanisi (ukuze uzivikele ekutholeni ukugxila kwekhibhodi) futhi usebenzise i-JavaScript yangokwezifiso ukuze ukhubaze ukusebenza kwazo.

I-plugin yenkinobho

Yenza okwengeziwe ngezinkinobho. Inkinobho yokulawula ithi noma dala amaqembu ezinkinobho zezingxenye ezengeziwe njengamabha wamathuluzi.

Guqula izifundazwe

Engeza data-toggle="button"ukuze uguqule isimo senkinobho active. Uma uguqula ngaphambili inkinobho, kufanele wengeze .activeikilasi mathupha kanye aria-pressed="true" naku- <button>.

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

Ibhokisi lokuhlola nezinkinobho zomsakazo

Izitayela ze -Bootstrap .buttonzingasetshenziswa kwezinye izici, ezifana no- <label>s, ukunikeza ibhokisi lokuhlola noma inkinobho yesitayela somsakazo. Engeza data-toggle="buttons"kokuqukethe .btn-grouplezo zinkinobho eziguquliwe ukuze unike amandla ukuziphatha kwazo kokuguqula nge-JavaScript futhi wengeze .btn-group-togglekusitayela u- <input>s ngaphakathi kwezinkinobho zakho. Qaphela ukuthi ungakha izinkinobho ezinamandla okufakwayo okukodwa noma amaqembu azo.

Isimo esithikhiwe salezi zinkinobho sibuyekezwa kuphela clickngomcimbi osenkinobho. Uma usebenzisa enye indlela ukuze ubuyekeze okokufaka—isb, usebenzisa <input type="reset">noma ngokufaka checkedimpahla yokokufaka ngokwakho—kuzodingeka uguqule .activengokuzenzela <label>.

Qaphela ukuthi izinkinobho ezihloliwe zidinga ukuthi ungeze .activeikilasi mathupha kokokufaka <label>.

<div class="btn-group-toggle" data-toggle="buttons">
  <label class="btn btn-secondary active">
    <input type="checkbox" checked autocomplete="off"> 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" autocomplete="off" checked> Active
  </label>
  <label class="btn btn-secondary">
    <input type="radio" name="options" id="option2" autocomplete="off"> Radio
  </label>
  <label class="btn btn-secondary">
    <input type="radio" name="options" id="option3" autocomplete="off"> Radio
  </label>
</div>

Izindlela

Indlela Incazelo
$().button('toggle') Iguqula isimo sohlelo. Inikeza inkinobho ukubonakala sengathi yenziwe yasebenza.
$().button('dispose') Icekela phansi inkinobho yento.