Nhwɛsoɔ ne dwumadie akwankyerɛ a ɛfa fom control styles, layout options, ne custom components a wɔde yɛ form ahodoɔ pii.
Nsɛm a Wɔaka abom
Bootstrap no fom controls no trɛw yɛn Rebooted form styles no mu ne adesua ahorow. Fa saa adesua ahorow yi di dwuma fa paw wɔn nkyerɛkyerɛmu a wɔahyɛ da ayɛ no mu ma nkyerɛase a ɛkɔ so daa wɔ browser ne mfiri ahorow nyinaa so.
Hwɛ sɛ wode typesu a ɛfata bedi dwuma wɔ nsɛm a wɔde ahyɛ mu nyinaa so (sɛ nhwɛso no, emailama imel address anaa numberakontaabu ho nsɛm) de anya nsɛm a wɔde hyɛ mu no sohwɛ foforo te sɛ imel nokwaredi, nɔma a wɔpaw, ne nea ɛkeka ho no so mfaso.
Nhwɛsoɔ a ɛyɛ ntɛm a ɛbɛkyerɛ Bootstrap no form styles nie. Kɔ so kenkan ma nsɛm a ɛfa adesua ahorow a wɔhwehwɛ, kratasin nhyehyɛe, ne nea ɛkeka ho ho.
Fom a wɔde di dwuma
Wɔde adesuakuw no na ɛyɛ nkyerɛwee kwan so tumi ahorow—te sɛ <input>s, <select>s, ne <textarea>s—no sɛnea wɔyɛ .form-controlno. Nea ɛka ho ne ntadehyɛ ahorow a wɔde hwɛ sɛnea ɛte wɔ ɔkwan a ɛkɔ akyiri so, tebea a wɔde wɔn adwene si so, ne kɛseyɛ, ne nea ɛkeka ho.
Hwɛ hu sɛ wobɛhwehwɛ yɛn amanne nkrataa no mu na ama woakɔ so ayɛ style <select>s.
Sɛ wopɛ fael nsɛm a wɔde hyɛ mu a, sesa .form-controlma .form-control-file.
Sizing a wɔde yɛ nneɛma
Fa adesua ahorow te sɛ .form-control-lgne .form-control-sm.
Akenkan nkutoo
Fa readonlyboolean su no ka ho wɔ input bi so na asiw nsakrae a wɔbɛyɛ wɔ input no bo no mu. Nsɛm a wɔde kenkan nkutoo no da adi sɛ ɛyɛ hare (te sɛ nsɛm a wɔde hyɛ mu a wɔagyae mu no ara pɛ), nanso kura cursor a ɛwɔ hɔ no mu.
Nkyerɛwee a ɛnyɛ den nkutoo a wɔkenkan
Sɛ wopɛ sɛ wonya <input readonly>elements wɔ wo fom mu styled sɛ plain text a, fa .form-control-plaintextclass no yi default form field styling no na kora margin ne padding a ɛfata no so.
Range Nsɛm a Wɔde Hyehyɛ Mu
Set horizontally scrollable range inputs denam .form-control-range.
Nnaka a wɔde hyɛ mu ne radio ahorow
.form-checkWɔde , adesuakuw biako ma nsɛm a wɔde hyɛ mu ahorow abien no nyinaa a ɛma wɔn HTML nneɛma no nhyehyɛe ne wɔn nneyɛe tu mpɔn na ɛma default checkboxes ne radio ahorow no tu mpɔn . Nnaka a wɔde hyɛ mu no yɛ nea wɔde paw nneɛma biako anaa pii wɔ list bi mu, bere a radio ahorow no yɛ nea wɔde paw ɔkwan biako fi pii mu.
Wɔboa checkbox ne radio ahorow a wɔadi dɛm. Attribute no disabledde kɔla a ɛyɛ hann bedi dwuma de aboa akyerɛ input no tebea.
Checkboxes ne radio buttons boa HTML-based form validation na ɛma labels a ɛyɛ tiawa a wotumi nya. Sɛnea ɛte no, yɛn <input>s ne <label>s yɛ anuanom nneɛma a ɛne an <input>within a <label>. Eyi yɛ verbose kakra sɛnea ɛsɛ sɛ wokyerɛ idne forattributes de bata <input>ne <label>.
Default (a wɔaboaboa ano) .
Sɛnea wɔahyɛ no, wɔde checkbox ne radio dodow biara a ɛyɛ anuanom a wɔbɛn no ntɛm ara no bɛhyehyɛ no tẽẽ na wɔde .form-check.
Inline no mu
Kuw checkboxes anaa radio ahorow wɔ row koro no ara a ɛkɔ soro no so denam biribiara a wode bɛka ho .form-check-inlineno so .form-check.
Sɛ wɔmfa nkyerɛwde biara nka ho
Fa ka .position-staticinputs a ɛwɔ mu .form-checka enni label text biara ho. Kae sɛ wobɛda so ara de nkyerɛwde bi ama mfiridwuma a ɛboa (sɛ nhwɛso no, sɛ wode bedi dwuma aria-label).
Twa kwan
Esiane sɛ Bootstrap di dwuma display: blockna width: 100%ɛkame ayɛ sɛ ɛyɛ yɛn fom controls nyinaa nti, forms bɛ default stack vertically. Wobetumi de adesua foforo adi dwuma de ayɛ nsakrae wɔ nhyehyɛe yi mu wɔ krataa biara so.
Yɛ akuw ahorow
Adesuakuw .form-groupno ne ɔkwan a ɛyɛ mmerɛw a wɔfa so de nhyehyɛe bi ka nkrataa ahorow ho. Ɛma adesuakuw a ɛyɛ mmerɛw a ɛhyɛ labels, controls, mmoa nsɛm a wobetumi apaw, ne nkrasɛm a wɔde di nkrasɛm a wɔde ma no akuwakuw yiye ho nkuran. By default it only applies margin-bottom, nanso ɛfa styles afoforo wɔ mu .form-inlinesɛnea ɛho hia. Fa di dwuma wɔ <fieldset>s, <div>s, anaa ɛkame ayɛ sɛ ade foforo biara ho.
Fom grid no
Wobetumi de yɛn grid adesua ahorow no akyekye nkrataa a ɛyɛ den kɛse. Fa eyinom di dwuma ma fom nhyehyɛe a ɛhwehwɛ sɛ wɔde nkyerɛwde ahorow pii, ntrɛwmu ahorow, ne nhyehyɛe afoforo a wobɛpaw.
Nkyerɛwee row
Wubetumi nso sesa .rowama .form-row, yɛn gyinapɛn grid row no mu nsakrae a ɛbɔ default column gutters no so ma nhyehyɛe a ɛyɛ den na ɛyɛ ketewaa.
Wobetumi nso de grid nhyehyɛe no ayɛ nhyehyɛe ahorow a ɛyɛ den kɛse.
Ɔkwan a wɔfa so yɛ ade a ɛkɔ soro
Fa grid no yɛ horizontal forms denam .rowclass no a wode bɛka form groups ho na wode .col-*-*classes no adi dwuma de akyerɛ wo labels ne controls no trɛw. Hwɛ hu sɛ wode bɛka .col-form-labelwo <label>s nso ho sɛnea ɛbɛyɛ a wɔbɛyɛ vertically centered ne wɔn a ɛbata ho form controls.
Ɛtɔ mmere bi a, ebia ɛho behia sɛ wode margin anaa padding utilities di dwuma de yɛ saa alignment a edi mũ a wuhia no. Sɛ nhwɛso no, yɛayi nea padding-topɛwɔ yɛn stacked radio inputs label no so na ama nsɛm no mfiase no ahyia yiye.
Horizontal kratasin label no kɛseyɛ
Hwɛ hu sɛ wode .col-form-label-smanaa .col-form-label-lgwo <label>s anaa s bedi dwuma de adi ne <legend>kɛse no akyi yiye ..form-control-lg.form-control-sm
Kɔla a wɔde yɛ kɛse
Sɛnea wɔakyerɛ wɔ nhwɛso ahorow a atwam no mu no, yɛn grid nhyehyɛe no ma wo kwan ma wode .cols dodow biara gu a .rowanaa .form-row. Wɔbɛkyekyɛ ntrɛwmu a ɛwɔ hɔ no mu pɛpɛɛpɛ wɔ wɔn ntam. Wubetumi nso apaw wo nkyerɛwde ahorow no fã ketewaa bi de agye baabi kɛse anaa kakraa bi, bere a .cols a aka no kyekyɛ nkae no mu pɛpɛɛpɛ, a nkyerɛwde ahorow pɔtee bi te sɛ .col-7.
Auto-sizing a wɔde yɛ nneɛma
Nhwɛsoɔ a ɛwɔ aseɛ ha yi de flexbox utility di dwuma de hyɛ emu nsɛm no mfimfini gyina hɔ na ɛsesa .colkɔ .col-autosɛdeɛ ɛbɛyɛ a wo columns no bɛgye baabi dodoɔ a ɛhia nko ara. Sɛ yɛbɛka no ɔkwan foforo so a, kɔla no kɛse gyina emu nsɛm so.
Afei wubetumi remix saa bio ne size-specific column classes.
Fa .form-inlineadesua no kyerɛ label ahorow, fom controls, ne button ahorow a ɛtoatoa so wɔ row biako a ɛkɔ soro so. Fom sohwɛ a ɛwɔ inline fom mu no gu ahorow kakra wɔ wɔn default tebea no ho.
Controls yɛ display: flex, a ɛbubu HTML white space biara na ɛma wo kwan ma wode alignment control a ɛwɔ spacing ne flexbox utilities ma.
Controls ne input akuw gye width: autode bu Bootstrap default no width: 100%so .
Controls no pue wɔ inline mu nkutoo wɔ viewports a anyɛ yiye koraa no ne tɛtrɛtɛ yɛ 576px de bu akontaa ma viewports teateaa wɔ mobile devices so.
Ebia ɛho behia sɛ wode nsa di ankorankoro kratasin sohwɛ ahorow no trɛw ne sɛnea ɛne ntamgyinafo utilities (sɛnea wɔakyerɛ wɔ ase ha no) hyia no ho dwuma. Nea etwa to no, hwɛ hu sɛ wode a <label>bɛka kratasin biara sohwɛ ho bere nyinaa, sɛ ɛho hia mpo sɛ wode sie ahɔho a wɔnyɛ screenreader a wɔde .sr-only.
Wɔboa custom form controls ne selects nso.
Nneɛma foforo a wɔde besi nkyerɛwde a wɔde asie ananmu
Mfiridwuma a ɛboa te sɛ screen readers benya ɔhaw wɔ wo nkrataa no ho sɛ woamfa label anhyɛ biribiara a wode bɛhyɛ mu no mu a. Wɔ saa inline nkrataa yi ho no, wubetumi de .sr-onlyadesuakuw no asie nkyerɛwde ahorow no. Akwan foforo wɔ hɔ a wɔfa so de ahyɛnsode ma mfiridwuma a ɛboa, te sɛ aria-label, aria-labelledbyanaa titlesu no. Sɛ eyinom mu biara nni hɔ a, mfiridwuma a ɛboa no betumi de placeholdersu no adi dwuma, sɛ ɛwɔ hɔ a, nanso hyɛ no nsow sɛ wɔmfa nni dwuma placeholdersɛ akwan foforo a wɔfa so de nkyerɛwde gu so no ananmu.
Mmoa nsɛm
Wobetumi de .form-text(kan no na wonim no sɛ .help-blockwɔ v3 mu) ayɛ Block-level mmoa nsɛm a ɛwɔ nkrataa mu. Wobetumi de inline mmoa nkyerɛwee adi dwuma wɔ ɔkwan a ɛyɛ mmerɛw so denam inline HTML element biara ne mfaso adesua ahorow te sɛ .text-muted.
Mmoa nsɛm a wɔde bata kratasin sohwɛ ahorow ho
Ɛsɛ sɛ mmoa nsɛm no bata krataa sohwɛ a ɛfa aria-describedbysu no a wɔde bedi dwuma ho no ho pefee. Eyi bɛma wɔahwɛ ahu sɛ mfiridwuma a ɛboa—te sɛ screen readers—bɛbɔ mmoa nsɛm yi ho amanneɛ bere a nea ɔde di dwuma no de n’adwene si so anaasɛ ɔhyɛn control no mu no.
Mmoa nsɛm a ɛwɔ inputs ase no betumi ayɛ styled ne .form-text. Saa adesua yi de bi ka ho display: blockna ɛde top margin bi ka ho ma ɛyɛ mmerɛw sɛ wɔbɛma ntam kwan afi nsɛm a wɔde ahyɛ mu a ɛwɔ atifi hɔ no mu.
Ɛsɛ sɛ wo password no tenten yɛ nkyerɛwde 8-20, nkyerɛwde ne nɔma wom, na ɛnsɛ sɛ ɛwɔ ntam, nkyerɛwde soronko, anaa emoji.
Inline text betumi de inline HTML element biara a ɛyɛ nea wɔtaa de di dwuma (sɛ ɛyɛ <small>, <span>, anaa biribi foforo) adi dwuma a biribiara nni mu sɛ utility class.
Nkrataa a wɔadi dɛm
Fa disabledboolean attribute no ka ho wɔ input bi so na asiw ɔdefo nkitahodi ano na ama ayɛ te sɛ nea ɛyɛ hare.
Fa disabledattribute no ka a ho na <fieldset>ama controls a ɛwɔ mu no nyinaa ayɛ adwuma.
Kɔkɔbɔ a wɔde ankora ahorow ahyɛ mu
Sɛnea wɔahyɛ no, browser ahorow no bɛfa native form controls ( <input>, <select>ne <button>elements) a ɛwɔ a mu <fieldset disabled>nyinaa sɛ wɔagyae, na asiw keyboard ne mouse nkitahodi nyinaa ano wɔ wɔn so. Nanso, sɛ wo kratasin no nso de <a ... class="btn btn-*">nneɛma bi ka ho a, wɔbɛma eyinom kwan a ɛyɛ pointer-events: none. Sɛnea wɔahyɛ no nsow wɔ ɔfa a ɛfa disabled state ho ma buttons (na titiriw wɔ ɔfa ketewa a ɛfa anchor elements ho), saa CSS agyapade yi nnya nyɛɛ standardized na wonnya mmoa koraa wɔ Internet Explorer 10 mu, na ɛrensiw keyboard dwumadiefoɔ kwan sɛ wɔbɛyɛ saa tumi twe adwene si nkitahodi ahorow yi so anaasɛ ɛma ɛyɛ adwuma. Enti sɛnea ɛbɛyɛ a wubenya ahobammɔ no, fa JavaScript a wɔahyɛ da ayɛ no di dwuma na ma link ahorow a ɛtete saa no nyɛ adwuma.
Cross-browser a ɛne ne ho hyia
Bere a Bootstrap de saa akwan yi bedi dwuma wɔ browser ahorow nyinaa mu no, Internet Explorer 11 ne nea ɛwɔ ase ha no ntumi mmoa disabledsu no koraa wɔ <fieldset>. Fa JavaScript a wɔahyɛ da ayɛ no di dwuma na ma fieldset no nyɛ adwuma wɔ browser ahorow yi mu.
Nneɛma a Wɔde Di Dwuma
Fa nsɛm a ɛsom bo, a ɛyɛ adwuma ma wo dwumadiefoɔ no denam HTML5 kratasin a wɔde di dwuma so– a ɛwɔ yɛn brawsa a yɛboa nyinaa mu . Paw fi browser default validation feedback no mu, anaa fa custom messages di dwuma denam yɛn adesua ahorow a wɔasisi ne JavaScript a wɔde fi ase no so.
Mprempren yɛkamfo kyerɛ sɛ fa custom validation styles di dwuma, efisɛ native browser default validation messages no ntumi nhu mfiridwuma a ɛboa bere nyinaa wɔ browser ahorow nyinaa mu (titiriw no, Chrome wɔ desktop ne mobile so).
Sɛnea ɛyɛ adwuma
Sɛnea fom validation yɛ adwuma wɔ Bootstrap ho ni:
HTML kratasin a wɔde di dwuma no yɛ nea wɔde di dwuma denam CSS no pseudo-classes abien no so, :invalidne :valid. Ɛfa <input>, <select>, ne <textarea>element ahorow ho.
Bootstrap scopes :invalidne :validstyles to awofo .was-validatedadesua, mpɛn pii no wɔde di dwuma wɔ <form>. Sɛ ɛnte saa a, afuo biara a wɔhwehwɛ a enni botae no bɛda adi sɛ ɛnyɛ adwuma wɔ kratafa a wɔde hyɛ mu. Saa kwan yi so no, wubetumi apaw bere a wode bɛyɛ adwuma (mpɛn pii no bere a wɔabɔ mmɔden sɛ wode kratasin bɛmena akyi).
Sɛ wopɛ sɛ wosan siesie kratasin no hwɛbea (sɛ nhwɛso no, wɔ krataa a wɔde mena a ɛyɛ nnam a wɔde AJAX di dwuma ho no), yi .was-validatedadesua no fi <form>bio bere a wɔde amena no akyi.
Sɛ́ fallback, .is-invalidna .is-validwobetumi de adesua ahorow adi dwuma sen sɛ wɔde pseudo-klas ahorow no bedi dwuma ama server afã validation . Wɔnhwehwɛ sɛ wɔyɛ .was-validatedawofo adesua.
Esiane anohyeto ahorow a ɛwɔ sɛnea CSS yɛ adwuma mu nti, yentumi (mprempren) mfa styles nni dwuma wɔ a <label>a ɛba ansa na form control bi anim wɔ DOM no mu a JavaScript a wɔahyɛ da ayɛ no mmoa nka ho.
Nnɛyi brawsa nyinaa boa constraint validation API , JavaScript akwan a ɛtoatoa so a wɔfa so ma fom sohwɛ ahorow di dwuma.
Nsɛm a wɔde ma no betumi de browser defaults (sono ma browser biara, na ɛnam CSS so ntumi nkyerɛw) anaa yɛn nsɛm a wɔde ma a wɔahyɛ da ayɛ a HTML ne CSS foforo wom adi dwuma.
Wubetumi de nkrasɛm a wɔahyɛ da ayɛ a ɛkyerɛ sɛ ɛyɛ nokware ama setCustomValiditywɔ JavaScript mu.
Bere a ɛno wɔ w’adwenem no, susuw demo ahorow a edidi so yi ho ma yɛn custom form validation styles, optional server side classes, ne browser defaults.
Nneɛma a wɔde yɛ nneɛma a wɔahyɛ da ayɛ
Sɛ wopɛ Bootstrap fom validation nkrasɛm a wɔahyɛ da ayɛ a, ɛho behia sɛ wode novalidateboolean attribute no ka wo <form>. Wei ma browser default feedback adwinnade no nyɛ adwuma, nanso ɛda so ara ma kwan kɔ fom validation API ahorow a ɛwɔ JavaScript mu no so. Bɔ mmɔden sɛ wode kratasin a ɛwɔ ase ha no bɛmena; yɛn JavaScript no bɛtwa submit button no mu na ɛde nsɛm a ɛfa ho akɔma wo. Sɛ worebɔ mmɔden sɛ wode bɛmena a, wubehu :invalidne :validstyles a wɔde adi dwuma wɔ wo form controls no so.
Nsɛm a wɔde ma a wɔahyɛ da ayɛ no de kɔla a wɔahyɛ da ayɛ, ahye, adwene a wɔde si biribi so, ne akyi ahyɛnsode ahorow di dwuma de di nsɛm a wɔde ma no ho nkitaho yiye. Background icons for <select>s no wɔ hɔ ne .custom-select, na ɛnyɛ .form-control.
Browser no yɛ nea wɔahyɛ da ayɛ
W’ani nnye custom validation feedback messages anaa JavaScript a wobɛkyerɛw de asesa form suban ho? Ne nyinaa ye, wubetumi de browser no defaults adi dwuma. Bɔ mmɔden sɛ wode kratasin a ɛwɔ ase ha no bɛmena. Ɛgyina wo browser ne OS so no, wobɛhunu ɔkwan soronko kakra a wobɛfa so akyerɛ wo nsɛm.
Bere a wontumi mfa CSS nsiesie saa nsɛm a wɔka fa ho no, woda so ara betumi afa JavaScript so ayɛ nsɛm a wɔka kyerɛ no ho nhyehyɛe.
Server afã
Yɛhyɛ nyansa sɛ fa client-side validation di dwuma, nanso sɛ ɛba sɛ wopɛ server-side validation a, wubetumi de .is-invalidne .is-valid. Hyɛ no nsow sɛ .invalid-feedbackwɔboa nso wɔ adesua ahorow yi mu.
Nneɛma a wɔboa
Validation styles wɔ hɔ ma form controls ne components a edidi so yi:
<input>s ne <textarea>s a ɛwɔ .form-control(a ɛkɔsi biako .form-controlwɔ nsɛm a wɔde hyɛ mu akuw mu ka ho) .
<select>s ne .form-controlanaa.custom-select
.form-checks
.custom-checkboxs ne .custom-radios
.custom-file
Nnwinnade Ho Afotu
Sɛ wo fom nhyehyeɛ ma ho kwan a, wobɛtumi asesa .{valid|invalid}-feedbackadesua ahodoɔ no ama .{valid|invalid}-tooltipadesua ahodoɔ no de akyerɛ validation feedback wɔ styled tooltip mu. Hwɛ hu sɛ wowɔ ɔwofo bi a position: relativeɔwɔ so ma adwinnade ho nsɛm a wɔde besi hɔ. Wɔ nhwɛsoɔ a ɛwɔ aseɛ ha yi mu no, yɛn column classes no wɔ yei dada, nanso wo project no betumi ahwehwɛ sɛ wobɛhyehyɛ foforɔ.
Nneɛma a Wɔyɛ no Sɛnea Wɔpɛ
Validation states betumi ayɛ customized via Sass ne $form-validation-statesmap no. Ɛwɔ yɛn _variables.scssfael no mu no, wɔde saa Sass map yi ayɛ loop de ayɛ default valid/ invalidvalidation states no. Nea ɛka ho ne nested map a wɔde sesa ɔman biara kɔla ne ahyɛnsode. Bere a aman foforo biara nni hɔ a browser ahorow boa no, wɔn a wɔde custom styles di dwuma no betumi de form feedback a ɛyɛ den kɛse aka ho ntɛm.
Yɛsrɛ wo hyɛ no nsow sɛ yɛnkamfo nkyerɛ sɛ wobɛsesa saa gyinapɛn ahorow yi a form-validation-statewonsakra mixin no nso.
Nkrataa a wɔahyɛ da ayɛ
Sɛ wopɛ sɛ woyɛ nsakrae pii mpo na ɛma wohu browser no pɛpɛɛpɛ a, fa yɛn form elements a wɔahyɛ da ayɛ no koraa no si browser defaults no ananmu. Wɔasi wɔ semantic ne accessible markup atifi, enti wɔyɛ solid replacements ma default form control biara.
Nnaka a wɔde hyɛ mu ne radio ahorow
Wɔde checkbox ne radio <input>ne <label>pairing biara abɔ mu <div>de ayɛ yɛn custom control. Wɔ nhyehyɛe mu no, eyi yɛ ɔkwan koro no ara a yɛn default no fa so .form-check.
Yɛde sibling selector ( ~) di dwuma ma yɛn <input>aman nyinaa —te sɛ :checked—de yɛ yɛn custom form indicator no sɛnea ɛfata. Sɛ yɛde ka .custom-control-labeladesuakuw no ho a, yebetumi nso ayɛ nsɛm a wɔakyerɛw ama ade biara a egyina <input>'s tebea so.
Yɛde default no sie <input>ne opacityna yɛde di dwuma .custom-control-labelde si custom form indicator foforo wɔ ne ananmu ne ::beforene ::after. Awerɛhosɛm ne sɛ yentumi nsi custom biako mfi kɛkɛ <input>efisɛ CSS's contentnyɛ adwuma wɔ saa element no so.
Wɔ tebea horow a wɔahwɛ mu no, yɛde base64 embedded SVG ahyɛnsode ahorow a efi Open Iconic . Eyi ma yenya tumi a eye sen biara ma styling ne positioning wɔ browser ne mfiri ahorow nyinaa so.
Nnaka a wɔde hyɛ mu
Custom checkboxes nso betumi de :indeterminatepseudo class no adi dwuma bere a wɔde nsa ahyɛ mu denam JavaScript so (HTML su biara nni hɔ a wɔde bɛkyerɛ).
Sɛ wode jQuery redi dwuma a, ɛsɛ sɛ biribi te sɛ eyi dɔɔso:
Radio ahorow
Inline no mu
Dɛmdie
Wobetumi asiw nnaka a wɔahyɛ da ayɛ ne radio ahorow nso ano. Fa disabledboolean attribute no ka ho <input>na custom indicator ne label nkyerɛkyerɛmu no bɛyɛ automatically styled.
Nsakrae ahorow
Switch bi wɔ markup a ɛwɔ custom checkbox nanso ɛde .custom-switchclass no di dwuma de kyerɛ toggle switch. Switches nso boa disabledattribute no.
Paw menu no
Custom <select>menus hia custom class nkutoo, .custom-selectna ama woatumi akanyan custom styles no. Custom styles no yɛ <select>'s mfiase anim nkutoo na entumi nsakra <option>s no esiane browser anohyeto ahorow nti.
Wubetumi nso apaw afi nketewa ne akɛse a wɔahyɛ da apaw mu ma ɛne yɛn nsɛm a wɔde hyɛ mu a ne kɛse yɛ pɛ no ahyia.
Wɔsan multiplenso boa su no:
Sɛnea sizesu no te no:
Dodoɔ
Yɛ custom <input type="range">controls a wode .custom-range. Wɔayɛ track (akyi) ne thumb (bo no) nyinaa sɛnea ɛbɛyɛ a ɛbɛda adi sɛ ɛyɛ pɛ wɔ browser ahorow no nyinaa so. Sɛnea IE ne Firefox nkutoo boa “hyɛ” wɔn track no ma fi nsateaa no benkum anaa nifa so sɛ ɔkwan a wɔfa so de aniwa kyerɛ nkɔso no, mprempren yɛnboa.
Range inputs wɔ implicit values ma minne max— 0ne 100, sɛnea ɛte biara. Wubetumi akyerɛ gyinapɛn foforo ama wɔn a wɔde minne maxsu ahorow no di dwuma no.
Sɛnea wɔahyɛ no, range inputs “snap” kɔ integer values so. Sɛ wopɛ sɛ wosakra eyi a, wubetumi akyerɛ stepbotae bi. Wɔ nhwɛso a ɛwɔ ase ha no mu no, yɛde anammɔn dodow no mmɔho abien denam step="0.5".
Fael browser no
Plugin a wɔkamfo kyerɛ sɛ ɛbɛma custom file input ayɛ adwuma: bs-custom-file-input , ɛno ne nea yɛde redi dwuma mprempren wɔ ha wɔ yɛn docs mu.
Fael input no yɛ gnarly sen biara wɔ bunch no mu na ɛhwehwɛ JavaScript foforo sɛ wopɛ sɛ wode hook wɔn ne functional Choose file... ne fael din text a woapaw.
Yɛde default fael no sie <input>via opacityna mmom yɛ style no <label>. Wɔyɛ bɔtn no na wɔde si hɔ ne ::after. Nea etwa to no, yɛpae mu ka sɛ a widthne heightwɔ so <input>ma ntam kwan a ɛfata ma nsɛm a atwa ho ahyia.
Nhama no a wɔde SCSS rekyerɛ ase anaasɛ wɔresakra no
Wɔde :lang()pseudo-class no di dwuma de ma kwan ma wɔkyerɛ “Browse” nsɛm no ase kɔ kasa afoforo mu. Fa kasa tag a ɛfa ho ne localized strings no to so anaa fa nsɛm a wɔakyerɛw no ka $custom-file-textSass variable no ho . Wobetumi ayɛ Engiresi nhama no ho nhyehyɛe saa ara. Sɛ nhwɛso no, sɛnea obi betumi de Spania nkyerɛase bi aka ho ni (Spanish kasa mmara ne ):es
Ɛha na lang(es)ɛreyɛ adwuma wɔ fael a wɔahyɛ da ahyɛ mu ama Spania nkyerɛase:
Ɛho behia sɛ wode wo krataa no kasa (anaasɛ ne dua ketewa) no si hɔ yiye sɛnea ɛbɛyɛ a wɔbɛda nsɛm a ɛteɛ adi. Wobetumi de attribute langa ɛwɔ <html>element no so anaa Content-LanguageHTTP header , ne akwan afoforo ayɛ eyi.
Nhama no a wobɛkyerɛ ase anaa wobɛsesa no denam HTML so
Bootstrap nso ma ɔkwan a wɔfa so kyerɛ “Browse” nkyerɛwee no ase wɔ HTML mu a data-browsesu a wobetumi de aka ahyɛnsode input label no ho (nhwɛso wɔ Dutch kasa mu):