Sib nrug
Bootstrap suav nrog ntau yam ntawm cov lus teb luv luv, padding, thiab cov chav kawm siv hluav taws xob sib txawv los hloov kho lub ntsiab lus.
Margin thiab padding
Muab cov lus teb rau cov phooj ywg margin
lossis cov padding
txiaj ntsig rau ib lub ntsiab lus lossis ib qho ntawm nws sab nrog cov chav kawm luv. Xws li kev txhawb nqa rau cov khoom ntiag tug, txhua yam khoom, thiab cov khoom ntsug thiab kab rov tav. Cov chav kawm yog tsim los ntawm lub neej ntawd Sass daim ntawv qhia xws li .25rem
mus rau 3rem
.
Siv CSS Grid layout module? Xav txog kev siv cov khoom siv sib txawv .
Lus cim
Cov khoom siv sib cais uas siv rau txhua qhov kev sib cais, los ntawm xs
mus rau xxl
, tsis muaj qhov luv luv ntawm lawv. Qhov no yog vim tias cov chav kawm no tau siv los ntawm min-width: 0
thiab nce, thiab yog li tsis muaj kev cuam tshuam los ntawm kev nug xov xwm. Cov seem breakpoints, txawm li cas los xij, suav nrog cov luv luv breakpoint.
Cov chav kawm muaj npe siv hom ntawv {property}{sides}-{size}
rau xs
thiab {property}{sides}-{breakpoint}-{size}
rau sm
, md
, lg
, xl
, thiab xxl
.
Qhov twg khoom yog ib qho ntawm:
m
- rau cov chav kawm uas teemmargin
p
- rau cov chav kawm uas teempadding
Qhov twg sab yog ib qho ntawm:
t
- rau cov chav kawm uas teemmargin-top
los yogpadding-top
b
- rau cov chav kawm uas teemmargin-bottom
los yogpadding-bottom
s
- (pib) rau cov chav kawm uas teeb tsamargin-left
lossispadding-left
hauv LTR,margin-right
lossispadding-right
hauv RTLe
- (kawg) rau cov chav kawm uas teevmargin-right
lossispadding-right
hauv LTR,margin-left
lossispadding-left
hauv RTLx
- rau cov chav kawm uas teem ob qho tib si*-left
thiab*-right
y
- rau cov chav kawm uas teem ob qho tib si*-top
thiab*-bottom
- dawb paug - rau cov chav kawm uas teem ib
margin
los yogpadding
tag nrho 4 sab ntawm lub caij
Qhov loj me yog ib qho ntawm:
0
- rau cov chav kawm uas tshem tawmmargin
lossispadding
los ntawm kev teeb tsa0
1
- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsamargin
lossispadding
rau$spacer * .25
2
- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsamargin
lossispadding
rau$spacer * .5
3
- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsamargin
lossispadding
rau$spacer
4
- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsamargin
lossispadding
rau$spacer * 1.5
5
- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsamargin
lossispadding
rau$spacer * 3
auto
- rau cov chav kawm uas teemmargin
rau auto
(Koj tuaj yeem ntxiv qhov ntau thiab tsawg los ntawm kev ntxiv nkag rau $spacers
Sass daim ntawv qhia hloov pauv.)
Piv txwv
Nov yog qee qhov piv txwv ntawm cov chav kawm no:
.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;
}
Kab rov tav centering
Tsis tas li ntawd, Bootstrap tseem suav nrog cov .mx-auto
chav kawm rau kab rov tav nruab nrab qhov dav-dav thaiv cov ntsiab lus - uas yog, cov ntsiab lus uas muaj display: block
thiab width
teeb tsa - los ntawm kev teeb tsa cov kab rov tav rau auto
.
<div class="mx-auto" style="width: 200px;">
Centered element
</div>
Negative margin
Hauv CSS, margin
cov khoom siv tuaj yeem siv cov txiaj ntsig tsis zoo ( padding
tsis tuaj yeem). Cov npoo tsis zoo no raug cuam tshuam los ntawm lub neej ntawd , tab sis tuaj yeem ua rau hauv Sass los ntawm kev teeb tsa $enable-negative-margins: true
.
Cov syntax yuav luag zoo ib yam li lub neej ntawd, cov txiaj ntsig zoo, tab sis nrog qhov sib ntxiv ntawm n
ua ntej qhov kev thov loj. Ntawm no yog ib qho piv txwv chav kawm uas yog qhov opposite ntawm .mt-1
:
.mt-n1 {
margin-top: -0.25rem !important;
}
Gap
Thaum siv display: grid
, koj tuaj yeem siv cov gap
khoom siv hluav taws xob ntawm niam txiv kab sib txuas. Qhov no tuaj yeem txuag tau ntawm kev ntxiv cov nqi hluav taws xob rau ib tus neeg cov khoom siv (cov menyuam yaus ntawm lub display: grid
thawv). Gap utilities yog teb los ntawm lub neej ntawd, thiab yog tsim los ntawm peb cov khoom siv API, raws li $spacers
Sass daim ntawv qhia.
<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>
Kev txhawb nqa suav nrog cov kev xaiv teb rau txhua qhov ntawm Bootstrap cov phiaj xwm tawg, nrog rau rau qhov ntau thiab tsawg los ntawm $spacers
daim ntawv qhia ( 0
– 5
). Tsis muaj .gap-auto
chav kawm siv hluav taws xob vim nws ua tau zoo ib yam li .gap-0
.
Sass
Maps
Qhov chaw siv hluav taws xob tau tshaj tawm los ntawm Sass daim ntawv qhia thiab tom qab ntawd tsim nrog peb cov khoom siv API.
$spacer: 1rem;
$spacers: (
0: 0,
1: $spacer * .25,
2: $spacer * .5,
3: $spacer,
4: $spacer * 1.5,
5: $spacer * 3,
);
$negative-spacers: if($enable-negative-margins, negativify-map($spacers), null);
Utilities API
Qhov chaw siv hluav taws xob tau tshaj tawm hauv peb cov khoom siv hluav taws xob API hauv scss/_utilities.scss
. Kawm paub siv cov khoom siv hluav taws xob API li cas.
"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
),