Tombol
Gunakake gaya tombol khusus Bootstrap kanggo tumindak ing formulir, dialog, lan liya-liyane kanthi dhukungan kanggo macem-macem ukuran, negara, lan liya-liyane.
Bootstrap kalebu sawetara gaya tombol sing wis ditemtokake, saben duwe tujuan semantik dhewe, kanthi sawetara tambahan sing dibuwang kanggo kontrol liyane.
<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>
Nuduhake makna kanggo teknologi assistive
Nggunakake warna kanggo nambah makna mung menehi indikasi visual, sing ora bakal dikirim menyang pangguna teknologi bantu - kayata pembaca layar. Priksa manawa informasi sing dituduhake kanthi warna katon jelas saka isi kasebut (umpamane teks sing katon), utawa kalebu liwat cara alternatif, kayata teks tambahan sing didhelikake karo .sr-only
kelas.
Kelas .btn
kasebut dirancang kanggo digunakake karo <button>
unsur kasebut. Nanging, sampeyan uga bisa nggunakake kelas iki ing <a>
utawa <input>
unsur (sanajan sawetara browser bisa nggunakake rendering rada beda).
Nalika nggunakake kelas tombol ing <a>
unsur sing digunakake kanggo micu fungsi ing kaca (kaya ambruk isi), tinimbang ngubungake menyang kaca anyar utawa bagean ing kaca saiki, pranala iki kudu diwenehi role="button"
kanggo tepat ngirim tujuane kanggo teknologi bantuan kayata maca layar.
<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">
Mbutuhake tombol, nanging ora werna latar mburi dibalèkaké padha nggawa? Ganti kelas modifier standar karo .btn-outline-*
sing kanggo mbusak kabeh gambar latar mburi lan werna ing tombol sembarang.
<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>
Apik tombol luwih gedhe utawa luwih cilik? Tambah .btn-lg
utawa .btn-sm
kanggo ukuran tambahan.
<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>
Nggawe tombol tingkat pemblokiran-sing ukurane jembar lengkap saka wong tuwa-kanthi nambahake .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>
Tombol bakal katon dipencet (kanthi latar mburi sing luwih peteng, wates sing luwih peteng, lan bayangan inset) nalika aktif. Ora perlu nambah kelas kanggo <button>
s amarga padha nggunakake pseudo-kelas . Nanging, sampeyan isih bisa meksa katon aktif padha karo .active
(lan kalebu aria-pressed="true"
atribut) yen sampeyan kudu nurun negara programmatically.
<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>
Nggawe tombol katon ora aktif kanthi nambahake disabled
atribut boolean menyang <button>
unsur apa wae.
<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>
Tombol sing dipateni nggunakake <a>
unsur tumindak rada beda:
<a>
s ora ndhukungdisabled
atribut, dadi sampeyan kudu nambah.disabled
kelas kanggo nggawe visual katon dipatèni.- Sawetara gaya ramah mangsa kalebu kanggo mateni kabeh
pointer-events
tombol anchor. Ing browser sing ndhukung properti kasebut, sampeyan ora bakal bisa ndeleng kursor sing dipateni. - Tombol sing dipatèni kudu kalebu
aria-disabled="true"
atribut kanggo nunjukake status unsur kanggo teknologi bantu.
<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>
Kaveat fungsi link
Kelas .disabled
digunakake pointer-events: none
kanggo nyoba mateni fungsi link <a>
s, nanging properti CSS durung standar. Kajaba iku, sanajan ing browser sing ndhukung pointer-events: none
, pandhu arah keyboard tetep ora kena pengaruh, tegese pangguna keyboard sing katon lan pangguna teknologi pitulung isih bisa ngaktifake tautan kasebut. Supaya aman, tambahake tabindex="-1"
atribut ing tautan kasebut (kanggo nyegah supaya ora nampa fokus keyboard) lan gunakake JavaScript khusus kanggo mateni fungsine.
Apa liyane karo tombol. Tombol kontrol nyatakake utawa nggawe klompok tombol kanggo komponen liyane kaya toolbar.
Tambah data-toggle="button"
kanggo ngalih status tombol active
. Yen sampeyan wis ngowahi tombol, sampeyan kudu nambahake .active
kelas lan aria-pressed="true"
menyang <button>
.
<button type="button" class="btn btn-primary" data-toggle="button" aria-pressed="false" autocomplete="off">
Single toggle
</button>
Gaya Bootstrap .button
bisa diterapake ing unsur liyane, kayata <label>
s, kanggo nyedhiyakake kothak centhang utawa tombol gaya radio. Tambah data-toggle="buttons"
menyang sing .btn-group
ngemot tombol sing diowahi kanggo ngaktifake prilaku toggling liwat JavaScript lan nambah .btn-group-toggle
gaya <input>
s ing tombol sampeyan. Elinga yen sampeyan bisa nggawe tombol siji input-powered utawa klompok saka wong-wong mau.
Negara sing dicenthang kanggo tombol kasebut mung dianyari liwat click
acara ing tombol kasebut. Yen sampeyan nggunakake cara liya kanggo nganyari input-contone, kanthi <input type="reset">
utawa kanthi manual ngetrapake checked
properti input-sampeyan kudu ngalih .active
kanthi <label>
manual.
Elinga yen tombol sing wis dicenthang mbutuhake sampeyan nambahake kelas kanthi manual .active
menyang input <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>
Metode | Katrangan |
---|---|
$().button('toggle') |
Ngalih status push. Menehi tombol katon sing wis diaktifake. |
$().button('dispose') |
Ngancurake tombol unsur. |