Izinkinobho
Sebenzisa izitayela zezinkinobho zangokwezifiso ze-Bootstrap ngezenzo ngamafomu, izingxoxo, nokuningi ngosekelo losayizi abaningi, izifunda, nokuningi.
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-only
nekilasi.
Amakilasi .btn
aklanyelwe 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 <a>
ezici ezisetshenziselwa 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.
<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">
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>
Uyathanda izinkinobho ezinkulu noma ezincane? Engeza .btn-lg
noma .btn-sm
osayizi 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>
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>
Yenza izinkinobho zibukeke zingasebenzi ngokwengeza disabled
isibaluli 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 azisekelidisabled
isibaluli, ngakho-ke kufanele wengeze.disabled
ikilasi ukuze ulenze libonakale likhubazekile.- Ezinye izitayela ezilungele ikusasa zifakiwe ukuze kukhubazwe konke
pointer-events
kuzinkinobho 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" role="button" aria-disabled="true">Primary link</a>
<a href="#" class="btn btn-secondary btn-lg disabled" role="button" aria-disabled="true">Link</a>
Xhumanisa i-caveat yokusebenza
The .disabled
class uses pointer-events: none
to try to disable the link functionality of <a>
s, but that CSS property is not yet standardized. In addition, even in browsers that do support pointer-events: none
, keyboard navigation remains unaffected, meaning that sighted keyboard users and users of assistive technologies will still be able to activate these links. So to be safe, add a tabindex="-1"
attribute on these links (to prevent them from receiving keyboard focus) and use custom JavaScript to disable their functionality.
Do more with buttons. Control button states or create groups of buttons for more components like toolbars.
Add data-toggle="button"
to toggle a button’s active
state. If you’re pre-toggling a button, you must manually add the .active
class and aria-pressed="true"
to the <button>
.
<button type="button" class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off">
Single toggle
</button>
Bootstrap’s .button
styles can be applied to other elements, such as <label>
s, to provide checkbox or radio style button toggling. Add data-toggle="buttons"
to a .btn-group
containing those modified buttons to enable their toggling behavior via JavaScript and add .btn-group-toggle
to style the <input>
s within your buttons. Note that you can create single input-powered buttons or groups of them.
The checked state for these buttons is only updated via click
event on the button. If you use another method to update the input—e.g., with <input type="reset">
or by manually applying the input’s checked
property—you’ll need to toggle .active
on the <label>
manually.
Qaphela ukuthi izinkinobho ezihloliwe zidinga ukuthi ungeze .active
ikilasi 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>
Indlela | Incazelo |
---|---|
$().button('toggle') |
Iguqula isimo sohlelo. Inikeza inkinobho ukubonakala sengathi yenziwe yasebenza. |
$().button('dispose') |
Icekela phansi inkinobho yento. |