Tlula eka nhlokomhaka-nkulu Tlula eka docs navigation
in English

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 marginkumbe paddingvalues ​​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 .25remku ya eka 3rem.

Ku tirhisa modyuli ya xivumbeko xa CSS Grid? Anakanya hi ku tirhisa xitirhisiwa xa gap .

Notation

Switirhisiwa swa ku hambanyisa leswi tirhaka eka tindhawu hinkwato to wisa, ku suka eka xsku 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: 0na 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 xsna {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- ya titlilasi leti vekaka margin-topkumbepadding-top
  • b- ya titlilasi leti vekaka margin-bottomkumbepadding-bottom
  • s- (ku sungula) eka titlilasi leti vekaka margin-leftkumbe padding-lefteka LTR, margin-rightkumbe padding-righteka RTL
  • e- (end) eka titlilasi leti vekaka margin-rightkumbe padding-righteka LTR, margin-leftkumbe padding-lefteka RTL
  • x- eka titlilasi leti vekaka havumbirhi bya swona *-leftna*-right
  • y- eka titlilasi leti vekaka havumbirhi bya swona *-topna*-bottom
  • blank - ya titlilasi leti vekaka a marginkumbe paddingeka matlhelo hinkwawo ya 4 ya elemente

Laha sayizi yi nga yin’wana ya:

  • 0- eka titlilasi leti herisaka marginkumbe paddinghi ku yi veka eka0
  • 1- (hi ku tiyimisela) eka titlilasi leti vekaka marginkumbe paddingku$spacer * .25
  • 2- (hi ku tiyimisela) eka titlilasi leti vekaka marginkumbe paddingku$spacer * .5
  • 3- (hi ku tiyimisela) eka titlilasi leti vekaka marginkumbe paddingku$spacer
  • 4- (hi ku tiyimisela) eka titlilasi leti vekaka marginkumbe paddingku$spacer * 1.5
  • 5- (hi ku tiyimisela) eka titlilasi leti vekaka marginkumbe paddingku$spacer * 3
  • auto- ya titlilasi leti vekaka marginku auto

(U nga engetela vukulu byin’wana hi ku engetela swilo leswi nghenisiweke eka $spacersxihlawulekisi 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-autotlilasi yo veka exikarhi hi ndlela yo olova nhundzu ya xiyimo xa xibokisana xa ku anama loku nga cinciki—hileswaku, nhundzu leyi nga display: blockni widthsete—hi ku veka swiphemu leswi nga etlhelo eka auto.

Xiaki lexi nga exikarhi
<div class="mx-auto" style="width: 200px;">
  Centered element
</div>

Margin ya negative

Eka CSS, marginswihlawulekisi swi nga tirhisa mimpimo yo biha ( paddinga 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 nemahlweni 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 gapswitirhisiwa 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: gridxikhomela). Switirhisiwa swa Gap swa hlamula hi ku tiyimisela, naswona swi endliwa hi ku tirhisa API ya hina ya switirhisiwa, hi ku ya hi $spacersmepe wa Sass.

Nchumu wa gridi 1
Nchumu wa gridi 2
Nchumu wa gridi 3
<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 $spacersmepe ( 05). Ku hava .gap-autotlilasi 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,
);

$negative-spacers: if($enable-negative-margins, negativify-map($spacers), null);

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
    ),