Rekọja si akoonu akọkọ Rekọja si lilọ kiri awọn iwe aṣẹ
in English

Awọn eroja

Kọ ẹkọ bii ati idi ti a fi kọ gbogbo awọn paati wa ni idahun ati pẹlu ipilẹ ati awọn kilasi iyipada.

Awọn kilasi mimọ

Awọn paati Bootstrap jẹ itumọ pupọ pẹlu nomenclature ipilẹ-atunṣe. A ṣe akojọpọ bi ọpọlọpọ awọn ohun-ini pinpin bi o ti ṣee ṣe sinu kilasi ipilẹ, bii .btn, ati lẹhinna ṣe akojọpọ awọn ara ẹni kọọkan fun iyatọ kọọkan si awọn kilasi iyipada, bii .btn-primarytabi .btn-success.

Lati kọ awọn kilasi iyipada wa, a lo awọn @eachlosiwajulosehin Sass lati ṣe iwọn lori maapu Sass kan. Eyi ṣe iranlọwọ paapaa fun ṣiṣẹda awọn iyatọ ti paati nipasẹ wa $theme-colorsati ṣiṣẹda awọn iyatọ idahun fun aaye fifọ kọọkan. Bi o ṣe n ṣe awọn maapu Sass wọnyi ti o si tun ṣe akopọ, iwọ yoo rii laifọwọyi awọn ayipada rẹ ti farahan ninu awọn yipo wọnyi.

Ṣayẹwo awọn maapu Sass wa ati awọn docs loops fun bi o ṣe le ṣe akanṣe awọn losiwajulosehin wọnyi ki o fa ọna iyipada-ipilẹ Bootstrap si koodu tirẹ.

Awọn oluyipada

Ọpọlọpọ awọn paati Bootstrap ni a kọ pẹlu ọna kilasi iyipada-ipilẹ. Eyi tumọ si pupọ julọ ti iselona wa ninu kilasi mimọ (fun apẹẹrẹ, .btn) lakoko ti awọn iyatọ ara wa ni ihamọ si awọn kilasi iyipada (fun apẹẹrẹ, .btn-danger). Awọn kilasi modifier wọnyi ni a kọ lati $theme-colorsmaapu lati ṣe isọdi nọmba ati orukọ awọn kilasi iyipada wa.

Eyi ni awọn apẹẹrẹ meji ti bii a ṣe yipo lori $theme-colorsmaapu lati ṣe ipilẹṣẹ awọn iyipada si .alertati awọn .list-grouppaati.

// 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);
}

Idahun

Awọn yipo Sass wọnyi ko ni opin si awọn maapu awọ, boya. O tun le ṣe ina awọn iyatọ idahun ti awọn paati rẹ. Mu fun apẹẹrẹ titete idahun wa ti awọn isọ silẹ nibiti a ti dapọ @eachlupu kan fun $grid-breakpointsmaapu Sass pẹlu ibeere media kan pẹlu.

// 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;
      }
    }
  }
}

Ti o ba tun ṣe atunṣe rẹ $grid-breakpoints, awọn ayipada rẹ yoo kan si gbogbo awọn losiwajulosehin ti n ṣe atunṣe lori maapu yẹn.

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

Fun alaye diẹ sii ati awọn apẹẹrẹ lori bii o ṣe le yipada awọn maapu Sass wa ati awọn oniyipada, jọwọ tọka si apakan Sass ti iwe Grid .

Ṣiṣẹda ti ara rẹ

A gba ọ niyanju lati gba awọn itọnisọna wọnyi nigbati o ba kọ Bootstrap lati ṣẹda awọn paati tirẹ. A ti faagun ọna yii funrara wa si awọn paati aṣa ninu iwe ati awọn apẹẹrẹ wa. Awọn paati bii awọn ipe wa ni a ṣe gẹgẹ bi awọn paati ti a pese pẹlu ipilẹ ati awọn kilasi iyipada.

Eleyi jẹ ipe kan. A kọ ọ ni aṣa fun awọn iwe aṣẹ wa nitorinaa awọn ifiranṣẹ wa si ọ duro jade. O ni awọn iyatọ mẹta nipasẹ awọn kilasi modifier.
<div class="callout">...</div>

Ninu CSS rẹ, iwọ yoo ni nkan bi atẹle nibiti o ti ṣe pupọ julọ ti aṣa nipasẹ .callout. Lẹhinna, awọn aṣa alailẹgbẹ laarin iyatọ kọọkan jẹ iṣakoso nipasẹ kilasi modifier.

// Base class
.callout {}

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

Fun awọn ipe, aṣa alailẹgbẹ yẹn jẹ kan border-left-color. Nigbati o ba darapọ kilasi ipilẹ yẹn pẹlu ọkan ninu awọn kilasi iyipada yẹn, o gba idile paati pipe rẹ:

Eyi jẹ ipe ipe alaye. Ọrọ apẹẹrẹ lati fihan ni iṣe.
Eyi jẹ ipe ikilọ kan. Ọrọ apẹẹrẹ lati fihan ni iṣe.
Eyi jẹ ipe ti ewu. Ọrọ apẹẹrẹ lati fihan ni iṣe.