API ya utilitaire
API ya utilitaire ezali esaleli oyo esalemi na Sass mpo na kobimisa ba classes ya utilité.
Ba utilitaires ya Bootstrap esalemi na API ya utilitaire na biso mpe ekoki kosalelama mpo na ko modifier to ko prolonger ensemble na biso ya ba classes ya utilitaires par défaut na nzela ya Sass. API na biso ya utilitaire ezali na base ya série ya ba cartes ya Sass na ba fonctions pona ko générer ba familles ya ba classes na ba options ndenge na ndenge. Soki oyebi ba cartes ya Sass te, tanga likolo na ba docs officiels ya Sass pona kobanda.
Karte $utilities
ezali na ba utilitaires na biso nionso mpe na sima esangani na $utilities
carte personnalisé na yo, soki ezali. Carte ya utilitaire ezali na liste ya ba groupes ya utilité oyo ezali na ba clés oyo endimaka ba options oyo elandi:
Liponi | Lolenge | Valeur ya défaut | Ndimbola |
---|---|---|---|
property |
Esengami | – . | Kombo ya propriété, oyo ekoki kozala molongo to ensemble ya ba chaînes (ndakisa, ba paddings horizontales to ba marges). |
values |
Esengami | – . | Liste ya ba valeurs, to carte soki olingi te kombo ya classe ezala ndenge moko na valeur. Soki null esalelami lokola fungola ya karte, class ezali te liboso ya nkombo ya kelasi. |
class |
Soki olingi | ntina te | Kombo ya kelasi oyo esalemi. Soki epesami te mpe property ezali ensemble ya ba chaînes, class ekozala par défaut na élément ya liboso ya property array. Soki epesami te mpe property ezali molongo, values bafungola esalelami mpo na class bankombo. |
css-var |
Soki olingi | false |
Boolean mpo na kobimisa ba variables ya CSS na esika ya mibeko ya CSS. |
css-variable-name |
Soki olingi | ntina te | Nkombo ya momesano oyo ezali na liboso te mpo na variable ya CSS na kati ya ensemble ya mibeko. |
local-vars |
Soki olingi | ntina te | Carte ya ba variables ya CSS locale pona ko generer en plus ya mibeko ya CSS. |
state |
Soki olingi | ntina te | Liste ya ba variantes ya pseudo-classe (ndakisa, :hover to :focus ) ya kobimisa. |
responsive |
Soki olingi | false |
Boolean oyo ezali kolakisa soki esengeli kosala ba classes responsives. |
rfs |
Soki olingi | false |
Boolean mpo na ko permettre rescaling ya fluide na RFS . |
print |
Soki olingi | false |
Boolean oyo ezali kolakisa soki esengeli kosala ba classes ya impression. |
rtl |
Soki olingi | true |
Boolean oyo ezali kolakisa soki esengeli kobatela utilitaire na RTL. |
API elimbolaki
Ba variables nionso ya utilité ebakisami na $utilities
variable na kati ya _utilities.scss
feuille de style na biso. Groupe moko na moko ya ba utilités ezo monana eloko moko boye:
$utilities: (
"opacity": (
property: opacity,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Oyo ebimisaka makambo oyo elandi:
.opacity-0 { opacity: 0; }
.opacity-25 { opacity: .25; }
.opacity-50 { opacity: .5; }
.opacity-75 { opacity: .75; }
.opacity-100 { opacity: 1; }
Lopango
Esengeli property
kotiya fungola oyo esengeli mpo na utilitaire nionso, mpe esengeli kozala na propriété CSS ya malamu. Propriété oyo esalelami na ensemble ya mibeko ya utilitaire oyo esalemi. Ntango class
fungola elongolami, esalaka mpe lokola nkombo ya kelasi ya liboso. Tótalela likambo oyo text-decoration
ekoki kosalelama:
$utilities: (
"text-decoration": (
property: text-decoration,
values: none underline line-through
)
);
Bobimisi:
.text-decoration-none { text-decoration: none !important; }
.text-decoration-underline { text-decoration: underline !important; }
.text-decoration-line-through { text-decoration: line-through !important; }
Mituya ya bato
Salelá values
fungola mpo na kolakisa motuya nini mpo na oyo elakisami property
esengeli kosalelama na bankombo ya kelasi mpe mibeko oyo esalemi. Ekoki kozala liste to carte (etiamaki na ba utilitaires to na variable ya Sass).
Lokola liste, lokola na text-decoration
ba utilités :
values: none underline line-through
Lokola carte, lokola na opacity
ba utilités :
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
Lokola variable Sass oyo etie liste to carte, lokola na ba position
utilitaires na biso :
values: $position-values
Kelasi
Salelá class
option mpo na kobongola préfixe ya kelasi oyo esalelami na CSS oyo esangisi. Ndakisa, mpo na kobongola uta .opacity-*
na kino na .o-*
:
$utilities: (
"opacity": (
property: opacity,
class: o,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Bobimisi:
.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; }
Soki class: null
, ebimisaka bakelasi mpo na moko na moko ya values
bafungola:
$utilities: (
"visibility": (
property: visibility,
class: null,
values: (
visible: visible,
invisible: hidden,
)
)
);
Bobimisi:
.visible { visibility: visible !important; }
.invisible { visibility: hidden !important; }
Ba utilitaires ya variable ya CSS
Botia css-var
option boolean na true
mpe API ekobimisa ba variables ya CSS ya esika mpo na moponi oyo epesami na esika ya property: value
mibeko ya momesano. Bakisa option moko css-variable-name
pona kotiya kombo ya variable CSS ekeseni na kombo ya classe.
Talá biloko oyo tosalelaka mpo na .text-opacity-*
kosalela biloko na biso. Soki tobakisi css-variable-name
option, tokozua sortie personnalisée.
$utilities: (
"text-opacity": (
css-var: true,
css-variable-name: text-alpha,
class: text-opacity,
values: (
25: .25,
50: .5,
75: .75,
100: 1
)
),
);
Bobimisi:
.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; }
Ba variables ya CSS ya esika
Salelá local-vars
option mpo na kolakisa carte ya Sass oyo ekobimisa ba variables ya CSS ya esika na kati ya ensemble ya mibeko ya classe ya utilitaire. Svp yeba ete ekoki kosenga mosala ya kobakisa mpo na kolya ba variables wana ya CSS ya esika na mibeko ya CSS oyo esalemi. Na ndakisa, tótalela makambo oyo tosalelaka mpo na .bg-*
kosalela biloko ya mosala:
$utilities: (
"background-color": (
property: background-color,
class: bg,
local-vars: (
"bg-opacity": 1
),
values: map-merge(
$utilities-bg-colors,
(
"transparent": transparent
)
)
)
);
Bobimisi:
.bg-primary {
--bs-bg-opacity: 1;
background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;
}
Ba Etats
Salelá state
option mpo na kobimisa ba variations ya pseudo-classe. Ndakisa ba pseudo-classes ezali :hover
mpe :focus
. Tango liste ya ba états epesami, ba kombo ya ba classes esalemi pona pseudo-classe wana. Par exemple, pona ko changer opacité na hover, bakisa state: hover
pe okozua .opacity-hover:hover
na CSS na yo compilé.
Esengeli na ba pseudo-classes ebele? Salelá liste ya ba états oyo ekabolami na esika: state: hover focus
.
$utilities: (
"opacity": (
property: opacity,
class: opacity,
state: hover,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Bobimisi:
.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; }
Koyanola
Bakisa responsive
boolean mpo na kobimisa ba utilitaires ya eyano (ndakisa, .opacity-md-25
) na kati ya ba points de rupture nionso .
$utilities: (
"opacity": (
property: opacity,
responsive: true,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Bobimisi:
.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; }
}
Imprimer
Kofungola print
option ekosala mpe ba classes ya utilitaire mpo na impression, oyo esalelamaka kaka na kati ya @media print { ... }
requête ya media.
$utilities: (
"opacity": (
property: opacity,
print: true,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Bobimisi:
.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; }
}
Ntina ya ntina
Ba utilitaires nionso oyo esalemi na API esangisi !important
pona ko assurer que ba overrider ba composants na ba classes ya modificateur ndenge esengelaki. Okoki kobongola paramètre oyo na mokili mobimba na $enable-important-utilities
variable (ezali na ndenge ya liboso na true
).
Kosalela API
Sikoyo lokola oyebi malamu ndenge API ya ba utilitaires esalaka, yekola ndenge ya kobakisa ba classes na yo moko ya personnalisé mpe kobongola ba utilitaires na biso ya défaut.
Kolongola ba utilitaires
Bolongola ba utilitaires oyo ezali na kosalelaka fungola moko. Ndakisa, soki olingi ba classes ya utilitaire ya débordement réponse ya kobakisa, okoki kosala boye:
$utilities: (
"overflow": (
responsive: true,
property: overflow,
values: visible hidden scroll auto,
),
);
Bakisa ba utilités
Ba utilitaires ya sika ekoki kobakisama na $utilities
carte par défaut na map-merge
. Sala que ba fichiers na biso ya Sass oyo esengeli pe _utilities.scss
ezala importé liboso, sima salela map-merge
pona kobakisa ba utilitaires na yo ya kobakisa. Ndakisa, awa ezali ndenge ya kobakisa cursor
utilitaire oyo ezo répondre na ba valeurs misato.
@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";
Bobongola ba utilités
$utilities
Modifier ba utilitaires existants na carte par défaut na na map-get
ba map-merge
fonctions. Na ndakisa oyo ezali awa na nse, tozali kobakisa motuya mosusu na ba width
utilitaires. Bandá na ebandeli map-merge
mpe na nsima lakisá utilitaire nini olingi kobongisa. "width"
Uta kuna, zwa carte encastrée na mpo na map-get
ko accéder mpe ko modifier ba options mpe ba valeurs ya utilitaire.
@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";
Activer ya ko répondre
Okoki ko activer ba classes responsives pona ensemble ya ba utilitaires existants oyo ezali responsive te na tango oyo par défaut. Na ndakisa, mpo na kosala ete border
bakelasi ezala na eyano:
@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";
Yango ekobimisa sikoyo ba variations responsives ya .border
mpe .border-0
mpo na point de rupture moko na moko. CSS na yo oyo osali ekozala boye:
.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 { ... }
}
Bobongola nkombo ya ba utilitaires
Ba utilitaires v4 ezangi, to omesana na convention mosusu ya kopesa ba kombo? API ya ba utilitaires ekoki kosalelama mpo na koboya résultat class
ya utilitaire moko epesami —ndakisa, kobongola kombo .ms-*
ya ba utilitaires na vieux .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";
Longola ba utilités
Longola moko ya ba utilitaires par défaut na map-remove()
fonction 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";
Okoki mpe kosalela map-merge()
fonction Sass mpe kotya touche ya groupe na mpo null
na kolongola utilitaire.
@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";
Bakisa, longola, kobongisa
Okoki kobakisa, kolongola, mpe kobongisa ba utilitaires mingi na mbala moko na map-merge()
fonction Sass . Tala ndenge okoki kosangisa bandakisa oyo eleki na karte moko ya monene.
@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";
Longola utilitaire na RTL
Ba cas mosusu ya bord esalaka que RTL styling ezala difficile , lokola ba line breaks na Arabe. Na yango ba utilitaires ekoki kobwakama na sortie RTL na kotiya rtl
option na false
:
$utilities: (
"word-wrap": (
property: word-wrap word-break,
class: text,
values: (break: break-word),
rtl: false
),
);
Bobimisi:
/* rtl:begin:remove */
.text-break {
word-wrap: break-word !important;
word-break: break-word !important;
}
/* rtl:end:remove */
Yango ebimisaka eloko te na RTL, grâce na directive ya contrôle ya RTLCSSremove
.