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

Cheebtsam

Kawm yuav ua li cas thiab yog vim li cas peb tsim ze li ntawm tag nrho peb cov Cheebtsam teb thiab nrog lub hauv paus thiab modifier chav kawm.

Ntawm nplooj ntawv no

Cov chav kawm hauv paus

Bootstrap cov khoom feem ntau ua nrog lub hauv paus-modifier nomenclature. Peb pab pawg sib koom ntau li ntau tau rau hauv cov chav kawm hauv paus, zoo li .btn, thiab tom qab ntawd pab pawg neeg tus qauv rau txhua qhov sib txawv rau hauv cov chav kawm hloov kho, nyiam .btn-primarylossis .btn-success.

Txhawm rau tsim peb cov chav kawm hloov kho, peb siv Sass's @eachloops los iterate hla Sass daim ntawv qhia. Qhov no yog qhov tshwj xeeb tshaj yog pab rau kev tsim cov kev sib txawv ntawm cov khoom siv los ntawm peb $theme-colorsthiab tsim cov kev hloov pauv rau txhua qhov kev tawg. Thaum koj kho cov Sass maps thiab rov ua dua, koj yuav pom koj cov kev hloov pauv tshwm sim hauv cov voj voog no.

Mus saib peb Sass maps thiab loops docs rau yuav ua li cas los kho cov voj voog no thiab txuas ntxiv Bootstrap lub hauv paus-modifier mus kom ze rau koj tus kheej cov cai.

Hloov kho

Ntau yam ntawm Bootstrap cov khoom yog tsim nrog lub hauv paus-modifier class mus kom ze. Qhov no txhais tau hais tias feem ntau ntawm cov styling muaj nyob rau hauv cov chav kawm (piv txwv li, .btn) thaum style variations raug txwv rau cov chav kawm hloov kho (xws li, .btn-danger). Cov chav kawm hloov kho no yog tsim los ntawm $theme-colorsdaim ntawv qhia kom kho tus lej thiab lub npe ntawm peb cov chav kawm hloov kho.

Nov yog ob qho piv txwv ntawm yuav ua li cas peb voj hla $theme-colorsdaim ntawv qhia los tsim cov kev hloov pauv rau cov khoom .alertthiab .list-groupcov khoom.

// Generate contextual modifier classes for colorizing the alert.

@each $state, $value in $theme-colors {
  $alert-background: shift-color($value, $alert-bg-scale);
  $alert-border: shift-color($value, $alert-border-scale);
  $alert-color: shift-color($value, $alert-color-scale);

  @if (contrast-ratio($alert-background, $alert-color) < $min-contrast-ratio) {
    $alert-color: mix($value, color-contrast($alert-background), abs($alert-color-scale));
  }
  .alert-#{$state} {
    @include alert-variant($alert-background, $alert-border, $alert-color);
  }
}
// List group contextual variants
//
// Add modifier classes to change text and background color on individual items.
// Organizationally, this must come after the `:hover` states.

@each $state, $value in $theme-colors {
  $list-group-variant-bg: shift-color($value, $list-group-item-bg-scale);
  $list-group-variant-color: shift-color($value, $list-group-item-color-scale);
  @if (contrast-ratio($list-group-variant-bg, $list-group-variant-color) < $min-contrast-ratio) {
    $list-group-variant-color: mix($value, color-contrast($list-group-variant-bg), abs($list-group-item-color-scale));
  }

  @include list-group-item-variant($state, $list-group-variant-bg, $list-group-variant-color);
}

Teb

Cov Sass loops no tsis txwv rau cov duab kos duab, ib yam nkaus. Koj tseem tuaj yeem tsim cov kev hloov pauv ntawm koj cov khoom. Ua piv txwv peb cov lus teb kev sib dhos ntawm cov kev poob qis uas peb sib tov ib lub @eachvoj rau $grid-breakpointsSass daim ntawv qhia nrog cov lus nug hauv xov xwm suav nrog.

// We deliberately hardcode the `bs-` prefix because we check
// this custom property in JS to determine Popper's positioning

@each $breakpoint in map-keys($grid-breakpoints) {
  @include media-breakpoint-up($breakpoint) {
    $infix: breakpoint-infix($breakpoint, $grid-breakpoints);

    .dropdown-menu#{$infix}-start {
      --bs-position: start;

      &[data-bs-popper] {
        right: auto;
        left: 0;
      }
    }

    .dropdown-menu#{$infix}-end {
      --bs-position: end;

      &[data-bs-popper] {
        right: 0;
        left: auto;
      }
    }
  }
}

Yog tias koj hloov kho koj $grid-breakpoints, koj cov kev hloov pauv yuav siv rau txhua lub voj voog iterating hla daim ntawv qhia ntawd.

$grid-breakpoints: (
  xs: 0,
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1200px,
  xxl: 1400px
);

Yog xav paub ntxiv thiab cov piv txwv txog kev hloov kho peb Sass maps thiab variables, thov mus saib ntawm Sass seem ntawm daim phiaj ntaub ntawv .

Tsim koj tus kheej

Peb xav kom koj coj cov lus qhia no thaum tsim nrog Bootstrap los tsim koj tus kheej cov khoom. Peb tau txuas ntxiv txoj hauv kev no rau peb tus kheej rau cov khoom siv hauv peb cov ntaub ntawv thiab cov piv txwv. Cheebtsam zoo li peb cov callouts tau tsim ib yam li peb cov khoom siv nrog cov hauv paus thiab cov chav kawm hloov kho.

Qhov no yog hu ua. Peb tsim nws kev cai rau peb cov ntaub ntawv kom peb cov lus rau koj sawv tawm. Nws muaj peb qhov sib txawv ntawm cov chav kawm hloov kho.
<div class="callout">...</div>

Hauv koj li CSS, koj yuav muaj qee yam zoo li hauv qab no qhov twg feem ntau ntawm cov styling ua tiav ntawm .callout. Tom qab ntawd, cov qauv tshwj xeeb ntawm txhua qhov sib txawv yog tswj los ntawm cov chav kawm hloov kho.

// Base class
.callout {}

// Modifier classes
.callout-info {}
.callout-warning {}
.callout-danger {}

Rau cov callouts, qhov tshwj xeeb styling tsuas yog ib qho border-left-color. Thaum koj muab cov chav kawm hauv qab no nrog ib qho ntawm cov chav kawm hloov kho, koj tau txais koj tsev neeg ua tiav:

Qhov no yog ib qho info callout. Piv txwv cov ntawv los qhia nws hauv kev nqis tes ua.
Nov yog lus ceeb toom. Piv txwv cov ntawv los qhia nws hauv kev nqis tes ua.
Qhov no yog ib tug txaus ntshai hu. Piv txwv cov ntawv los qhia nws hauv kev nqis tes ua.