Hla mus rau cov ntsiab lus tseem ceeb Hla mus rau docs navigation
Check
in English

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 marginlossis cov paddingtxiaj 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 .25remmus rau 3rem.

Siv CSS Grid layout module? Xav txog kev siv qhov khoom siv sib txawv xwb.

Lus cim

Cov khoom siv sib cais uas siv rau txhua qhov kev sib cais, los ntawm xsmus rau xxl, tsis muaj qhov luv luv ntawm lawv. Qhov no yog vim tias cov chav kawm no tau siv los ntawm min-width: 0thiab 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 xsthiab {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 teem margin-toplos yogpadding-top
  • b- rau cov chav kawm uas teem margin-bottomlos yogpadding-bottom
  • s- (pib) rau cov chav kawm uas teeb tsa margin-leftlossis padding-lefthauv LTR, margin-rightlossis padding-righthauv RTL
  • e- (kawg) rau cov chav kawm uas teev margin-rightlossis padding-righthauv LTR, margin-leftlossis padding-lefthauv RTL
  • x- rau cov chav kawm uas teem ob qho tib si *-leftthiab*-right
  • y- rau cov chav kawm uas teem ob qho tib si *-topthiab*-bottom
  • dawb paug - rau cov chav kawm uas teem ib marginlos yog paddingtag nrho 4 sab ntawm lub caij

Qhov loj me yog ib qho ntawm:

  • 0- rau cov chav kawm uas tshem tawm marginlossis paddinglos ntawm kev teeb tsa0
  • 1- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsa marginlossis paddingrau$spacer * .25
  • 2- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsa marginlossis paddingrau$spacer * .5
  • 3- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsa marginlossis paddingrau$spacer
  • 4- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsa marginlossis paddingrau$spacer * 1.5
  • 5- (los ntawm lub neej ntawd) rau cov chav kawm uas teeb tsa marginlossis paddingrau$spacer * 3
  • auto- rau cov chav kawm uas teem marginrau auto

(Koj tuaj yeem ntxiv qhov ntau thiab tsawg los ntawm kev ntxiv nkag rau $spacersSass 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-autochav kawm rau kab rov tav nruab nrab qhov dav-dav thaiv cov ntsiab lus - uas yog, cov ntsiab lus uas muaj display: blockthiab widthteeb tsa - los ntawm kev teeb tsa cov kab rov tav rau auto.

Lub ntsiab tseem ceeb
<div class="mx-auto" style="width: 200px;">
  Centered element
</div>

Negative margin

Hauv CSS, margincov khoom siv tuaj yeem siv cov txiaj ntsig tsis zoo ( paddingtsis 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 nua 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 gapkhoom siv hluav taws xob ntawm niam txiv kab sib txuas. Qhov no tuaj yeem txuag tau ntawm qhov yuav tsum tau ntxiv cov nqi hluav taws xob rau cov khoom siv ib leeg (cov menyuam yaus ntawm lub display: gridthawv). Gap utilities yog teb los ntawm lub neej ntawd, thiab yog tsim los ntawm peb cov nqi hluav taws xob API, raws li $spacersSass daim ntawv qhia.

Daim phiaj khoom 1
Daim phiaj khoom 2
Daim phiaj khoom 3
html
<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 $spacersdaim ntawv qhia ( 05). Tsis muaj .gap-autochav 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,
);

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
    ),
    // Gap utility
    "gap": (
      responsive: true,
      property: gap,
      class: gap,
      values: $spacers
    ),