Ku hambanisiwa ka swilo
Bootstrap yi katsa nxaxamelo wo anama wa titlilasi ta vukorhokeri bya margin lebyi hlamulaka hi shorthand, padding, na gap ku cinca xivumbeko xa elemente.
Margin na ku padding
Avela responsive-friendly margin
kumbe padding
values eka element kumbe subset ya matlhelo ya yona na titlilasi ta shorthand. Ku katsa na nseketelo wa swihlawulekisi swa munhu hi xiyexe, swihlawulekisi hinkwaswo, na swihlawulekisi leswi yimisiweke na leswi nga etlhelo. Titlilasi ti akiwile ku suka eka mepe wa Sass wa ntolovelo ku sukela eka .25rem
ku ya eka 3rem
.
Notation
Switirhisiwa swa ku hambanyisa leswi tirhaka eka tindhawu hinkwato to wisa, ku suka eka xs
ku ya eka xxl
, a swi na xifunengeto xa swiphemu swo tsema eka swona. Leswi swi vangiwa hikuva titlilasi teto ti tirhisiwa ku suka min-width: 0
na le henhla, naswona xisweswo a ti bohiwi hi xivutiso xa vuhangalasi bya mahungu. Hambiswiritano, swiphemu leswi saleke swa ku tshoveka swi katsa xifunengeto xa ku tshoveka.
Titlilasi ti thyiwile mavito hi ku tirhisa xivumbeko {property}{sides}-{size}
xa xs
na {property}{sides}-{breakpoint}-{size}
xa sm
, md
, lg
, xl
, na xxl
.
Laha nhundzu yi nga yin’wana ya:
m
- ya titlilasi leti vekakamargin
p
- ya titlilasi leti vekakapadding
Laha matlhelo ku nga rin’wana ra:
t
- eka titlilasi leti vekakamargin-top
kumbepadding-top
b
- eka titlilasi leti vekakamargin-bottom
kumbepadding-bottom
s
- (ku sungula) eka titlilasi leti vekakamargin-left
kumbepadding-left
eka LTR,margin-right
kumbepadding-right
eka RTLe
- (end) eka titlilasi leti vekakamargin-right
kumbepadding-right
eka LTR,margin-left
kumbepadding-left
eka RTLx
- eka titlilasi leti vekaka havumbirhi bya swona*-left
na*-right
y
- eka titlilasi leti vekaka havumbirhi bya swona*-top
na*-bottom
- blank - ya titlilasi leti vekaka a
margin
kumbepadding
eka matlhelo hinkwawo ya 4 ya elemente
Laha sayizi yi nga yin’wana ya:
0
- eka titlilasi leti herisakamargin
kumbepadding
hi ku yi veka eka0
1
- (hi ku tiyimisela) eka titlilasi leti vekakamargin
kumbepadding
ku$spacer * .25
2
- (hi ku tiyimisela) eka titlilasi leti vekakamargin
kumbepadding
ku$spacer * .5
3
- (hi ku tiyimisela) eka titlilasi leti vekakamargin
kumbepadding
ku$spacer
4
- (hi ku tiyimisela) eka titlilasi leti vekakamargin
kumbepadding
ku$spacer * 1.5
5
- (hi ku tiyimisela) eka titlilasi leti vekakamargin
kumbepadding
ku$spacer * 3
auto
- ya titlilasi leti vekakamargin
ku auto
(U nga engetela vukulu byin’wana hi ku engetela swilo leswi nghenisiweke eka $spacers
xihlawulekisi xa mepe wa Sass.)
Swikombiso
Hi leswi swikombiso swin’wana leswi yimelaka titlilasi leti:
.mt-0 {
margin-top: 0 !important;
}
.ms-1 {
margin-left: ($spacer * .25) !important;
}
.px-2 {
padding-left: ($spacer * .5) !important;
padding-right: ($spacer * .5) !important;
}
.p-3 {
padding: $spacer !important;
}
Ku vekiwa exikarhi ka horizontal
Ku engetela kwalaho, Bootstrap yi tlhela yi katsa .mx-auto
tlilasi yo veka exikarhi hi ndlela yo olova nhundzu ya xiyimo xa xibokisana xa ku anama loku nga cinciki—hileswaku, nhundzu leyi nga display: block
ni width
sete—hi ku veka swiphemu leswi nga etlhelo eka auto
.
<div class="mx-auto" style="width: 200px;">
Centered element
</div>
Margin ya negative
Eka CSS, margin
swihlawulekisi swi nga tirhisa mimpimo yo biha ( padding
a swi nge swi koti). Ti margin leti to biha ti pfaleriwile hi ku tiyimisela , kambe ti nga tirhisiwa eka Sass hi ku veka $enable-negative-margins: true
.
Xivumbeko xa marito xi le kusuhi no fana na switirhisiwa swa margin leswinene, swa xiviri, kambe hi ku engeteriwa ka n
emahlweni ka mpimo lowu komberiweke. Hi leyi tlilasi ya xikombiso leyi hambaneke na .mt-1
:
.mt-n1 {
margin-top: -0.25rem !important;
}
Vangwa
Loko u tirhisa display: grid
, u nga tirhisa gap
switirhisiwa eka xikhomela-ndhawu xa giridi ya mutswari. Leswi swi nga hlayisa mali eka ku boheka ku engetela switirhisiwa swa margin eka swilo swa gridi ha xin’we (vana va display: grid
xikhomela). Switirhisiwa swa Gap swa hlamula hi ku tiyimisela, naswona swi endliwa hi ku tirhisa API ya hina ya switirhisiwa, hi ku ya hi $spacers
mepe wa Sass.
<div class="d-grid gap-3">
<div class="p-2 bg-light border">Grid item 1</div>
<div class="p-2 bg-light border">Grid item 2</div>
<div class="p-2 bg-light border">Grid item 3</div>
</div>
Nseketelo wu katsa swihlawulekisi swo hlamula eka hinkwaswo swa ku tshoveka ka giridi ya Bootstrap, xikan’we na tisayizi ta tsevu ku suka eka $spacers
mepe ( 0
– 5
). Ku hava .gap-auto
tlilasi ya vukorhokeri tanihi leswi hi ndlela leyinene yi fanaka na .gap-0
.
Sass
Mimepe
Switirhisiwa swa ku hambana swi tivisiwa hi ku tirhisa mepe wa Sass ivi swi endliwa hi API ya hina ya switirhisiwa.
$spacer: 1rem;
$spacers: (
0: 0,
1: $spacer * .25,
2: $spacer * .5,
3: $spacer,
4: $spacer * 1.5,
5: $spacer * 3,
);
API ya switirhisiwa
Switirhisiwa swa ku hambana swi tivisiwile eka API ya hina ya switirhisiwa hi scss/_utilities.scss
. Dyondza ndlela yo tirhisa API ya switirhisiwa.
"margin": (
responsive: true,
property: margin,
class: m,
values: map-merge($spacers, (auto: auto))
),
"margin-x": (
responsive: true,
property: margin-right margin-left,
class: mx,
values: map-merge($spacers, (auto: auto))
),
"margin-y": (
responsive: true,
property: margin-top margin-bottom,
class: my,
values: map-merge($spacers, (auto: auto))
),
"margin-top": (
responsive: true,
property: margin-top,
class: mt,
values: map-merge($spacers, (auto: auto))
),
"margin-end": (
responsive: true,
property: margin-right,
class: me,
values: map-merge($spacers, (auto: auto))
),
"margin-bottom": (
responsive: true,
property: margin-bottom,
class: mb,
values: map-merge($spacers, (auto: auto))
),
"margin-start": (
responsive: true,
property: margin-left,
class: ms,
values: map-merge($spacers, (auto: auto))
),
// Negative margin utilities
"negative-margin": (
responsive: true,
property: margin,
class: m,
values: $negative-spacers
),
"negative-margin-x": (
responsive: true,
property: margin-right margin-left,
class: mx,
values: $negative-spacers
),
"negative-margin-y": (
responsive: true,
property: margin-top margin-bottom,
class: my,
values: $negative-spacers
),
"negative-margin-top": (
responsive: true,
property: margin-top,
class: mt,
values: $negative-spacers
),
"negative-margin-end": (
responsive: true,
property: margin-right,
class: me,
values: $negative-spacers
),
"negative-margin-bottom": (
responsive: true,
property: margin-bottom,
class: mb,
values: $negative-spacers
),
"negative-margin-start": (
responsive: true,
property: margin-left,
class: ms,
values: $negative-spacers
),
// Padding utilities
"padding": (
responsive: true,
property: padding,
class: p,
values: $spacers
),
"padding-x": (
responsive: true,
property: padding-right padding-left,
class: px,
values: $spacers
),
"padding-y": (
responsive: true,
property: padding-top padding-bottom,
class: py,
values: $spacers
),
"padding-top": (
responsive: true,
property: padding-top,
class: pt,
values: $spacers
),
"padding-end": (
responsive: true,
property: padding-right,
class: pe,
values: $spacers
),
"padding-bottom": (
responsive: true,
property: padding-bottom,
class: pb,
values: $spacers
),
"padding-start": (
responsive: true,
property: padding-left,
class: ps,
values: $spacers
),
// Gap utility
"gap": (
responsive: true,
property: gap,
class: gap,
values: $spacers
),