Amaqhosha
Sebenzisa izimbo zeqhosha le-Bootstrap ukwenza izinto kwiifom, iingxoxo, kunye nokunye ngenkxaso yeesayizi ezininzi, amazwe, kunye nokunye.
I-Bootstrap ibandakanya izitayile zamaqhosha achazwe kwangaphambili, nganye isebenzela injongo yayo ye-semantic, kunye nokongezwa okumbalwa okuphoswe kulawulo olungaphezulu.
<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>
Ukuhambisa intsingiselo kwiiteknoloji ezincedisayo
Ukusebenzisa umbala ukongeza intsingiselo kubonelela kuphela ngesalathiso esibonakalayo, esingayi kuthunyelwa kubasebenzisi betekhnoloji encedisayo - njengezifundi zesikrini. Qinisekisa ukuba ulwazi olubonakaliswe ngumbala lucacile kumxholo ngokwawo (umzekelo, umbhalo obonakalayo), okanye luqukwe ngezinye iindlela, ezifana nesicatshulwa esongezelelweyo esifihlwe .sr-only
eklasini.
Iiklasi .btn
ziyilelwe ukuba zisetyenziswe kunye <button>
nesiqalelo. Nangona kunjalo, ungasebenzisa ezi klasi kwi <a>
okanye <input>
izinto (nangona ezinye iibhrawuza zinokusebenzisa unikezelo olwahluke kancinane).
Xa usebenzisa iiklasi zamaqhosha <a>
kwizinto ezisetyenziselwa ukuqalisa ukusebenza kwekhasi (njengomxholo odilikayo), endaweni yokudibanisa amaphepha amatsha okanye amacandelo angaphakathi kwephepha langoku, la makhonkco kufuneka anikwe role="button"
ukuhambisa ngokufanelekileyo injongo yawo kubuchwephesha obuncedisayo njenge abafundi besikrini.
<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">
Ngaba ufuna iqhosha, kodwa hayi imibala engasemva enzima abayizisayo? Buyisela iiklasi zesilungisi esingagqibekanga ngezo .btn-outline-*
zokususa yonke imifanekiso yangasemva kunye nemibala kulo naliphi na iqhosha.
<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>
Unqwenela amaqhosha amakhulu okanye amancinci? Yongeza .btn-lg
okanye .btn-sm
iisayizi ezongezelelweyo.
<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>
Yenza amaqhosha omgangatho webhlokhi—awo anobubanzi obupheleleyo bomzali—ngokongeza .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>
Amaqhosha azakuvela ecinezelwe (ngemvelaphi emnyama, umda omnyama, kunye nesithunzi somfanekiso) xa usebenza. Akukho mfuneko yokongeza iklasi ku- <button>
s njengoko besebenzisa i-pseudo-class . Nangona kunjalo, usenakho ukunyanzela inkangeleko efanayo esebenzayo kunye .active
(kwaye ubandakanye aria-pressed="true"
uphawu) ukuba ufuna ukuphinda urhulumente ngokwenkqubo.
<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 amaqhosha abonakale engasebenzi ngokongeza disabled
uphawu lwe boolean kuyo nayiphi na <button>
into.
<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>
Amaqhosha angasebenziyo asebenzisa <a>
isiqalelo aziphathe ngokwahlukileyo:
<a>
s ayiluxhasidisabled
uphawu, ngoko ke kufuneka udibanise.disabled
iklasi ukuyenza ibonakale ingasebenzi.- Ezinye izimbo ezilungele ixesha elizayo zibandakanyiwe ukuvala zonke
pointer-events
kumaqhosha eankile. Kwibhrawuza ezixhasa lo propati, awuzukubona ikhesa ekhubazekileyo kwaphela. - Amaqhosha avaliweyo kufuneka abandakanye
aria-disabled="true"
uphawu lokubonisa imeko yento kwiitekhnoloji ezincedisayo.
<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>
Icaveat yokusebenza kwekhonkco
Iklasi .disabled
isebenzisa pointer-events: none
ukuzama ukukhubaza usebenziso lwekhonkco lwe- <a>
s, kodwa loo propati ye-CSS ayikabikho emgangathweni. Ukongeza, nakwiziphequluli ezixhasayo pointer-events: none
, ukukhangela kwekhibhodi kuhlala kungachaphazeleki, okuthetha ukuba abasebenzisi bekhibhodi ababoniweyo kunye nabasebenzisi bobuchwephesha bokuncedisa baya kuba nakho ukwenza la makhonkco asebenze. Ke ukuze ukhuseleke, yongeza tabindex="-1"
uphawu kula makhonkco (ukuwathintela ekufumaneni ujoliso lwebhodi yezitshixo) kwaye usebenzise iJavaScript yesiko ukukhubaza ukusebenza kwabo.
Yenza ngakumbi ngamaqhosha. Iqhosha lokulawula lixela okanye wenze amaqela amaqhosha amalungu amaninzi njengebar yesixhobo.
Yongeza data-toggle="button"
ukuguqula imeko yeqhosha active
. Ukuba ucofa ngaphambili iqhosha, kufuneka udibanise .active
iklasi ngesandla kwaye aria-pressed="true"
kwi <button>
.
<button type="button" class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off">
Single toggle
</button>
Izitayile zeBootstrap .button
zinokusetyenziswa kwezinye izinto, ezinje nge- <label>
s, ukunika ibhokisi yokukhangela okanye iqhosha lesimbo serediyo. Yongeza data-toggle="buttons"
kwi .btn-group
equlathe loo maqhosha alungisiweyo ukwenza ukuziphatha kwawo ujiko ngeJavaScript kwaye wongeze .btn-group-toggle
kwisimbo i <input>
s ngaphakathi kwamaqhosha akho. Qaphela ukuba ungenza amaqhosha afakwe amandla elinye okanye amaqela awo.
Imo ekhangelweyo kula maqhosha ihlaziywa kuphela click
ngesiganeko kwiqhosha. Ukuba usebenzisa enye indlela yokuhlaziya igalelo-umz., usebenzisa <input type="reset">
okanye ngokwenza ngesandla checked
ipropathi yegalelo-kuya kufuneka uguqule .active
ngokuzenzela <label>
.
Qaphela ukuba amaqhosha atshekishwe kwangaphambili afuna ukuba wongeze ngokwenza .active
iklasi kwigalelo <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 | Inkcazo |
---|---|
$().button('toggle') |
Itshintsha imeko yokutyhala. Inika iqhosha inkangeleko yokuba livuliwe. |
$().button('dispose') |
Itshabalalisa iqhosha lesiqalelo. |