I-Utility API
I-Utility API iyithuluzi elisekelwe kwa-Sass lokukhiqiza amakilasi osizo.
Izinsiza ze-Bootstrap zenziwa nge-API yethu yokusetshenziswa futhi zingasetshenziselwa ukuguqula noma ukunweba isethi yethu ezenzakalelayo yamakilasi okusetshenziswayo nge-Sass. I-API yethu yokusetshenziswa isekelwe ochungechungeni lwamamephu we-Sass nemisebenzi yokukhiqiza imindeni yamakilasi ngezinketho ezihlukahlukene. Uma ungawazi amamephu akwa-Sass, funda kumadokhumenti e- Sass asemthethweni ukuze uqalise.
Imephu $utilities
iqukethe zonke izinsiza zethu futhi kamuva ihlanganiswa $utilities
nemephu yakho yangokwezifiso, uma ikhona. Imephu yokusetshenziswa iqukethe uhlu olunokhiye lwamaqembu asetshenziswayo amukela izinketho ezilandelayo:
Inketho | Uhlobo | Inani elizenzakalelayo | Incazelo |
---|---|---|---|
property |
Kudingeka | - | Igama lesakhiwo, lokhu kungaba iyunithi yezinhlamvu noma uchungechunge lwezintambo (isb., amaphedi avundlile noma amamajini). |
values |
Kudingeka | - | Uhlu lwamanani, noma imephu uma ungafuni ukuthi igama lekilasi lifane nevelu. Uma null isetshenziswa njengokhiye wemephu, class ayinqunyelwe egameni lekilasi. |
class |
Ongakukhetha | null | Igama lekilasi elakhiwe. Uma inganikeziwe futhi property kuwuchungechunge lweyunithi yezinhlamvu, class izozenzakalela ibe yisici sokuqala samalungu property afanayo. Uma kunganikeziwe futhi property kuwuchungechunge, values okhiye basetshenziselwa class amagama. |
css-var |
Ongakukhetha | false |
I-Boolean ukukhiqiza okuguquguqukayo kwe-CSS esikhundleni semithetho ye-CSS. |
css-variable-name |
Ongakukhetha | null | Igama langokwezifiso elinganqunyelwe lokuhluka kwe-CSS ngaphakathi kwesethi yomthetho. |
local-vars |
Ongakukhetha | null | Imephu yezinto eziguquguqukayo zendawo ze-CSS ezizokhiqizwa ngaphezu kwemithetho ye-CSS. |
state |
Ongakukhetha | null | Uhlu lwezinhlobonhlobo zesigaba-mbumbulu (isb, :hover noma :focus ) okumelwe zenziwe. |
responsive |
Ongakukhetha | false |
I-Boolean ekhombisa uma amakilasi asabelayo kufanele enziwe. |
rfs |
Ongakukhetha | false |
I-Boolean ukuze unike amandla ukukala kabusha koketshezi nge-RFS . |
print |
Ongakukhetha | false |
I-Boolean ekhombisa uma amakilasi okuphrinta adinga ukwenziwa. |
rtl |
Ongakukhetha | true |
I-Boolean ekhombisa ukuthi ukusetshenziswa kufanele kugcinwe ku-RTL. |
I-API yachaza
Zonke izinto eziguquguqukayo zengezwa $utilities
kokuguquguqukayo ngaphakathi kweshidi lethu _utilities.scss
lesitayela. Iqembu ngalinye lezinsiza libukeka kanje:
$utilities: (
"opacity": (
property: opacity,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Okukhipha okulandelayo:
.opacity-0 { opacity: 0; }
.opacity-25 { opacity: .25; }
.opacity-50 { opacity: .5; }
.opacity-75 { opacity: .75; }
.opacity-100 { opacity: 1; }
Impahla
Ukhiye odingekayo property
kufanele usethelwe noma iyiphi insiza, futhi kufanele uqukathe isakhiwo esivumelekile se-CSS. Lesi sici sisetshenziswa kusethi yemithetho yensiza ekhiqiziwe. Uma class
ukhiye ukhishiwe, uphinda usebenze njengegama lekilasi elimisiwe. Cabangela text-decoration
insiza:
$utilities: (
"text-decoration": (
property: text-decoration,
values: none underline line-through
)
);
Okukhiphayo:
.text-decoration-none { text-decoration: none !important; }
.text-decoration-underline { text-decoration: underline !important; }
.text-decoration-line-through { text-decoration: line-through !important; }
Amanani
Sebenzisa values
ukhiye ukuze ucacise ukuthi imaphi amanani ashiwo property
okufanele asetshenziswe kumagama ekilasi akhiqiziwe nemithetho. Kungaba uhlu noma imephu (esethwe ezintweni ezisetshenziswayo noma kokuguquguqukayo kwe-Sass).
Njengohlu, text-decoration
njengezinsiza :
values: none underline line-through
Njengemephu, opacity
njengezinsiza :
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
Njengokuguquguquka kwe-Sass osetha uhlu noma imephu, njengakuzinsiza position
zethu :
values: $position-values
Ikilasi
Sebenzisa class
inketho ukuze uguqule isiqalo sekilasi esisetshenziswe ku-CSS ehlanganisiwe. Isibonelo, ukushintsha kusuka .opacity-*
ku- .o-*
:
$utilities: (
"opacity": (
property: opacity,
class: o,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Okukhiphayo:
.o-0 { opacity: 0 !important; }
.o-25 { opacity: .25 !important; }
.o-50 { opacity: .5 !important; }
.o-75 { opacity: .75 !important; }
.o-100 { opacity: 1 !important; }
Uma class: null
, ikhiqiza amakilasi kukhiye ngamunye values
:
$utilities: (
"visibility": (
property: visibility,
class: null,
values: (
visible: visible,
invisible: hidden,
)
)
);
Okukhiphayo:
.visible { visibility: visible !important; }
.invisible { visibility: hidden !important; }
Izinsiza eziguquguqukayo ze-CSS
Setha css-var
inketho ye-boolean true
futhi i-API izokhiqiza okuguquguqukayo kwasendaweni kwe-CSS yesikhethi esinikeziwe esikhundleni property: value
semithetho evamile. Engeza ongakukhetha css-variable-name
ukuze usethe igama elihlukile le-CSS kunegama lekilasi.
Cabangela .text-opacity-*
izinsiza zethu. Uma singeza css-variable-name
inketho, sizothola okukhiphayo ngokwezifiso.
$utilities: (
"text-opacity": (
css-var: true,
css-variable-name: text-alpha,
class: text-opacity,
values: (
25: .25,
50: .5,
75: .75,
100: 1
)
),
);
Okukhiphayo:
.text-opacity-25 { --bs-text-alpha: .25; }
.text-opacity-50 { --bs-text-alpha: .5; }
.text-opacity-75 { --bs-text-alpha: .75; }
.text-opacity-100 { --bs-text-alpha: 1; }
Okuguquguqukayo kwendawo ye-CSS
Sebenzisa local-vars
inketho ukuze ucacise imephu ye-Sass ezokhiqiza okuguquguqukayo kwasendaweni kwe-CSS ngaphakathi kwesethi yemithetho yesigaba sosizo. Sicela uqaphele ukuthi kungase kudinge umsebenzi owengeziwe ukuze usebenzise lezo ziguquguqukayo zendawo ze-CSS emithethweni ekhiqiziwe ye-CSS. Isibonelo, cabanga .bg-*
ngezinsiza zethu:
$utilities: (
"background-color": (
property: background-color,
class: bg,
local-vars: (
"bg-opacity": 1
),
values: map-merge(
$utilities-bg-colors,
(
"transparent": transparent
)
)
)
);
Okukhiphayo:
.bg-primary {
--bs-bg-opacity: 1;
background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;
}
Amazwe
Sebenzisa state
inketho ukuze ukhiqize ukuhluka kwesigaba-mbumbulu. Izibonelo zamakilasi mbumbulu yilezi :hover
kanye :focus
. Uma uhlu lwezifunda lunikezwa, amagama ekilasi adalelwa leso sigaba-mbumbulu. Isibonelo, ukuze uguqule ukukhanya ku-hambisa phezulu, engeza state: hover
futhi uzongena .opacity-hover:hover
ku-CSS yakho ehlanganisiwe.
Udinga amakilasi-mbumbulu amaningi? Sebenzisa uhlu lwezifundazwe oluhlukaniswe isikhala: state: hover focus
.
$utilities: (
"opacity": (
property: opacity,
class: opacity,
state: hover,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Okukhiphayo:
.opacity-0-hover:hover { opacity: 0 !important; }
.opacity-25-hover:hover { opacity: .25 !important; }
.opacity-50-hover:hover { opacity: .5 !important; }
.opacity-75-hover:hover { opacity: .75 !important; }
.opacity-100-hover:hover { opacity: 1 !important; }
Iyasabela
Engeza i- responsive
boolean ukuze ukhiqize izinsiza ezisabelayo (isb, .opacity-md-25
) kuwo wonke ama-breakpoint .
$utilities: (
"opacity": (
property: opacity,
responsive: true,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Okukhiphayo:
.opacity-0 { opacity: 0 !important; }
.opacity-25 { opacity: .25 !important; }
.opacity-50 { opacity: .5 !important; }
.opacity-75 { opacity: .75 !important; }
.opacity-100 { opacity: 1 !important; }
@media (min-width: 576px) {
.opacity-sm-0 { opacity: 0 !important; }
.opacity-sm-25 { opacity: .25 !important; }
.opacity-sm-50 { opacity: .5 !important; }
.opacity-sm-75 { opacity: .75 !important; }
.opacity-sm-100 { opacity: 1 !important; }
}
@media (min-width: 768px) {
.opacity-md-0 { opacity: 0 !important; }
.opacity-md-25 { opacity: .25 !important; }
.opacity-md-50 { opacity: .5 !important; }
.opacity-md-75 { opacity: .75 !important; }
.opacity-md-100 { opacity: 1 !important; }
}
@media (min-width: 992px) {
.opacity-lg-0 { opacity: 0 !important; }
.opacity-lg-25 { opacity: .25 !important; }
.opacity-lg-50 { opacity: .5 !important; }
.opacity-lg-75 { opacity: .75 !important; }
.opacity-lg-100 { opacity: 1 !important; }
}
@media (min-width: 1200px) {
.opacity-xl-0 { opacity: 0 !important; }
.opacity-xl-25 { opacity: .25 !important; }
.opacity-xl-50 { opacity: .5 !important; }
.opacity-xl-75 { opacity: .75 !important; }
.opacity-xl-100 { opacity: 1 !important; }
}
@media (min-width: 1400px) {
.opacity-xxl-0 { opacity: 0 !important; }
.opacity-xxl-25 { opacity: .25 !important; }
.opacity-xxl-50 { opacity: .5 !important; }
.opacity-xxl-75 { opacity: .75 !important; }
.opacity-xxl-100 { opacity: 1 !important; }
}
Phrinta
Ukunika amandla print
inketho kuzophinda kukhiqize amakilasi ezinsiza zokuphrinta, asetshenziswa kuphela ngaphakathi @media print { ... }
kombuzo wemidiya.
$utilities: (
"opacity": (
property: opacity,
print: true,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Okukhiphayo:
.opacity-0 { opacity: 0 !important; }
.opacity-25 { opacity: .25 !important; }
.opacity-50 { opacity: .5 !important; }
.opacity-75 { opacity: .75 !important; }
.opacity-100 { opacity: 1 !important; }
@media print {
.opacity-print-0 { opacity: 0 !important; }
.opacity-print-25 { opacity: .25 !important; }
.opacity-print-50 { opacity: .5 !important; }
.opacity-print-75 { opacity: .75 !important; }
.opacity-print-100 { opacity: 1 !important; }
}
Ukubaluleka
Zonke izinsiza ezikhiqizwe i-API zifaka phakathi !important
ukuqinisekisa ukuthi zibhala ngaphezulu izingxenye namakilasi okulungisa njengoba kuhlosiwe. Ungakwazi ukuguqula lesi silungiselelo emhlabeni jikelele ngokushintshashintsha $enable-important-utilities
(okuzenzakalelayo kuye kokuthi true
).
Ukusebenzisa i-API
Manje njengoba usuyazi ukuthi i-API yezinsiza isebenza kanjani, funda ukuthi ungangeza kanjani amakilasi akho angokwezifiso futhi ulungise izinsiza zethu ezizenzakalelayo.
Khipha izinsiza
Khipha izinsiza ezikhona ngokusebenzisa ukhiye ofanayo. Isibonelo, uma ufuna amakilasi ezinsiza ezengeziwe eziphendulayo, ungenza lokhu:
$utilities: (
"overflow": (
responsive: true,
property: overflow,
values: visible hidden scroll auto,
),
);
Engeza izinsiza
Izinsiza ezintsha zingangezwa $utilities
kumephu ezenzakalelayo nge- map-merge
. Qiniseka ukuthi amafayela ethu adingekayo akwa-Sass futhi _utilities.scss
angeniswa kuqala, bese usebenzisa map-merge
ukungeza izinsiza zakho ezengeziwe. Isibonelo, nansi indlela yokwengeza cursor
insiza ephendulayo enamanani amathathu.
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"cursor": (
property: cursor,
class: cursor,
responsive: true,
values: auto pointer grab,
)
)
);
@import "bootstrap/scss/utilities/api";
Shintsha izinsiza
Lungisa izinsiza ezikhona $utilities
kumephu ezenzakalelayo map-get
kanye map-merge
nemisebenzi. Esibonelweni esingezansi, sengeza inani elingeziwe width
kuzinsiza. Qala nge-initial map-merge
bese usho ukuthi iyiphi insiza ofuna ukuyishintsha. Kusuka lapho, landa "width"
imephu ebekwe esidlekeni map-get
ukuze ufinyelele futhi ulungise izinketho namanani ensiza.
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"width": map-merge(
map-get($utilities, "width"),
(
values: map-merge(
map-get(map-get($utilities, "width"), "values"),
(10: 10%),
),
),
),
)
);
@import "bootstrap/scss/utilities/api";
Nika amandla ukuphendula
Unganika amandla amakilasi asabelayo kusethi ekhona yezinsiza okwamanje ezingasabeli ngokuzenzakalela. Isibonelo, ukwenza border
amakilasi aphendule:
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities, (
"border": map-merge(
map-get($utilities, "border"),
( responsive: true ),
),
)
);
@import "bootstrap/scss/utilities/api";
Lokhu manje kuzodala ukuhlukahluka okusabelayo kwephuzu .border
ngalinye .border-0
lokuhlukana. I-CSS yakho ekhiqiziwe izobukeka kanje:
.border { ... }
.border-0 { ... }
@media (min-width: 576px) {
.border-sm { ... }
.border-sm-0 { ... }
}
@media (min-width: 768px) {
.border-md { ... }
.border-md-0 { ... }
}
@media (min-width: 992px) {
.border-lg { ... }
.border-lg-0 { ... }
}
@media (min-width: 1200px) {
.border-xl { ... }
.border-xl-0 { ... }
}
@media (min-width: 1400px) {
.border-xxl { ... }
.border-xxl-0 { ... }
}
Qamba kabusha izinsiza
Izinsiza ze-v4 ezingekho, noma ezijwayele ukuqamba amagama? Izinsiza ze-API zingasetshenziselwa ukubhala ngaphezulu umphumela class
wokusetshenziswa okunikeziwe—ngokwesibonelo, ukuqamba kabusha .ms-*
izinsiza ziye ku-oldish .ml-*
:
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities, (
"margin-start": map-merge(
map-get($utilities, "margin-start"),
( class: ml ),
),
)
);
@import "bootstrap/scss/utilities/api";
Susa izinsiza
Susa noma yiziphi izinsiza ezizenzakalelayo ngomsebenzi we- map-remove()
Sass .
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities";
// Remove multiple utilities with a comma-separated list
$utilities: map-remove($utilities, "width", "float");
@import "bootstrap/scss/utilities/api";
Ungasebenzisa futhi map-merge()
umsebenzi we-Sass bese usetha ukhiye weqembu null
ukuze ususe insiza.
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"width": null
)
);
@import "bootstrap/scss/utilities/api";
Engeza, susa, lungisa
Ungangeza, ususe, futhi ulungise izinsiza eziningi ngesikhathi esisodwa ngomsebenzi we- map-merge()
Sass . Nansi indlela ongazihlanganisa ngayo izibonelo zangaphambilini wenze imephu eyodwa enkulu.
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
// Remove the `width` utility
"width": null,
// Make an existing utility responsive
"border": map-merge(
map-get($utilities, "border"),
( responsive: true ),
),
// Add new utilities
"cursor": (
property: cursor,
class: cursor,
responsive: true,
values: auto pointer grab,
)
)
);
@import "bootstrap/scss/utilities/api";
Susa isisetshenziswa ku-RTL
Amanye amakesi onqenqema enza isitayela se-RTL sibe nzima , njengokunqamuka kwemigqa ngesi-Arabhu. Ngakho izinsiza zingehliswa ekuphumeni kwe-RTL ngokusetha rtl
inketho kokuthi false
:
$utilities: (
"word-wrap": (
property: word-wrap word-break,
class: text,
values: (break: break-word),
rtl: false
),
);
Okukhiphayo:
/* rtl:begin:remove */
.text-break {
word-wrap: break-word !important;
word-break: break-word !important;
}
/* rtl:end:remove */
Lokhu akukhiphi lutho ku-RTL, ngenxa yomyalelo wokulawula we-RTLCSSremove
.