Tīpoka ki te ihirangi matua Tīpoka ki te whakaterenga tuhinga
in English

Papamuri

Whakaatuhia te tikanga background-colorme te taapiri i te whakapaipai me nga rōnaki.

Tae papamuri

He rite ki nga karaehe tae kuputuhi horopaki, tautuhia te papamuri o tetahi huānga ki tetahi karaehe horopaki. Ko nga taputapu papamuri kaore i te tautuhicolor , na i etahi wa ka hiahia koe ki te whakamahi i .text-* nga taputapu tae .

.bg-tuatahi
.bg-tuarua
.bg-angitu
.bg-mate
.bg-whakatupato
.bg-info
.bg-marama
.bg-pouri
.bg-tinana
.bg-ma
.bg-maataata
<div class="p-3 mb-2 bg-primary text-white">.bg-primary</div>
<div class="p-3 mb-2 bg-secondary text-white">.bg-secondary</div>
<div class="p-3 mb-2 bg-success text-white">.bg-success</div>
<div class="p-3 mb-2 bg-danger text-white">.bg-danger</div>
<div class="p-3 mb-2 bg-warning text-dark">.bg-warning</div>
<div class="p-3 mb-2 bg-info text-dark">.bg-info</div>
<div class="p-3 mb-2 bg-light text-dark">.bg-light</div>
<div class="p-3 mb-2 bg-dark text-white">.bg-dark</div>
<div class="p-3 mb-2 bg-body text-dark">.bg-body</div>
<div class="p-3 mb-2 bg-white text-dark">.bg-white</div>
<div class="p-3 mb-2 bg-transparent text-dark">.bg-transparent</div>

Rōnaki papamuri

Ma te taapiri i tetahi .bg-gradientkaraehe, ka taapirihia he rōnaki rārangi hei whakaahua papamuri ki nga papamuri. Ka timata te rōnaki ki te mā āhua pūataata ka memeha ki raro.

Kei te hiahia koe i te rōnaki i roto i to ritenga CSS? Tāpiri noa background-image: var(--bs-gradient);.

.bg-primary.bg-gradient
.bg-secondary.bg-gradient
.bg-success.bg-gradient
.bg-danger.bg-gradient
.bg-warning.bg-gradient
.bg-info.bg-gradient
.bg-light.bg-gradient
.bg-dark.bg-gradient

Opacity

Kua taapirihia ki te v5.1.0

Mai i te v5.1.0, background-colorka hangaia nga taputapu me Sass ma te whakamahi i nga taurangi CSS. Ma tenei ka taea te whakarereke i nga tae o te waa me te kore he whakahiato me nga huringa maramara alpha hihiri.

Pehea te mahi

Whakaarohia ta maatau .bg-successtaputapu taunoa.

.bg-success {
  --bs-bg-opacity: 1;
  background-color: rgba(var(--bs-success-rgb), var(--bs-bg-opacity)) !important;
}

Ka whakamahia e matou he putanga RGB o to maatau --bs-success(me te uara o te 25, 135, 84) taurangi CSS me te taapiri i tetahi taurangi CSS tuarua, --bs-bg-opacity, mo te marama o te alpha (me te uara taunoa he 1mihi ki tetahi taurangi CSS rohe). Ko te tikanga ka whakamahia e koe .bg-successinaianei, ko to coloruara tatau ko rgba(25, 135, 84, 1). Ko te taurangi CSS rohe kei roto i ia .bg-*karaehe ka karo i nga take tuku iho na reira karekau nga waahanga o nga taputapu e whiwhi aunoa i te maarama alpha whakarereke.

Tauira

Hei huri i taua puatakoretanga, whakakorehia --bs-bg-opacityma nga momo ritenga, me nga momo raina-roto.

He papamuri angitu taunoa tenei
Ko te 50% opacity angitu papamuri tenei
<div class="bg-success p-2 text-white">This is default success background</div>
<div class="bg-success p-2" style="--bs-bg-opacity: .5;">This is 50% opacity success background</div>

Ranei, whiriwhiri mai i tetahi o nga .bg-opacitytaputapu:

He papamuri angitu taunoa tenei
Koinei te 75% opacity angitu papamuri
Ko te 50% opacity angitu papamuri tenei
Ko te 25% opacity angitu papamuri tenei
Ko te 10% opacity angitu papamuri tenei
<div class="bg-success p-2 text-white">This is default success background</div>
<div class="bg-success p-2 text-white bg-opacity-75">This is 75% opacity success background</div>
<div class="bg-success p-2 text-dark bg-opacity-50">This is 50% opacity success background</div>
<div class="bg-success p-2 text-dark bg-opacity-25">This is 25% opacity success background</div>
<div class="bg-success p-2 text-dark bg-opacity-10">This is 10% opacity success background</div>

Sass

I tua atu i nga mahi a Sass e whai ake nei, whakaarohia te panui mo o maatau taonga ritenga CSS (aka CSS taurangi) mo nga tae me etahi atu.

Taurangi

Ko te nuinga o nga background-colortaputapu ka hangaia e o maatau tae kaupapa, kua tohua mai i a maatau taurangi papatae tae.

$blue:    #0d6efd;
$indigo:  #6610f2;
$purple:  #6f42c1;
$pink:    #d63384;
$red:     #dc3545;
$orange:  #fd7e14;
$yellow:  #ffc107;
$green:   #198754;
$teal:    #20c997;
$cyan:    #0dcaf0;
$primary:       $blue;
$secondary:     $gray-600;
$success:       $green;
$info:          $cyan;
$warning:       $yellow;
$danger:        $red;
$light:         $gray-100;
$dark:          $gray-900;
$gradient: linear-gradient(180deg, rgba($white, .15), rgba($white, 0));

Kei te waatea ano nga tae kirikiri, engari he waahanga iti ka whakamahia hei whakaputa taputapu.

$white:    #fff;
$gray-100: #f8f9fa;
$gray-200: #e9ecef;
$gray-300: #dee2e6;
$gray-400: #ced4da;
$gray-500: #adb5bd;
$gray-600: #6c757d;
$gray-700: #495057;
$gray-800: #343a40;
$gray-900: #212529;
$black:    #000;

Mapi

Ka tukuna nga tae kaupapa ki roto i te mapi Sass kia taea ai e tatou te huri ki runga ki te whakaputa i a tatou taputapu, whakarereke i nga waahanga, me etahi atu.

$theme-colors: (
  "primary":    $primary,
  "secondary":  $secondary,
  "success":    $success,
  "info":       $info,
  "warning":    $warning,
  "danger":     $danger,
  "light":      $light,
  "dark":       $dark
);

Kei te waatea ano nga tae kirikiri hei mapi Sass. Ko tenei mapi kaore e whakamahia ki te whakaputa taputapu.

$grays: (
  "100": $gray-100,
  "200": $gray-200,
  "300": $gray-300,
  "400": $gray-400,
  "500": $gray-500,
  "600": $gray-600,
  "700": $gray-700,
  "800": $gray-800,
  "900": $gray-900
);

Ko nga tae RGB he mea hanga mai i tetahi mahere Sass motuhake:

$theme-colors-rgb: map-loop($theme-colors, to-rgb, "$value");

Na ka hangaia nga opacity tae papamuri ki runga i a raatau ake mapi e pau ana e nga taputapu API:

$utilities-bg: map-merge(
  $utilities-colors,
  (
    "black": to-rgb($black),
    "white": to-rgb($white),
    "body": to-rgb($body-bg)
  )
);
$utilities-bg-colors: map-loop($utilities-bg, rgba-css-var, "$key", "bg");

Whakaranu

Karekau he ranunga e whakamahia ana hei whakaputa i a maatau taputapu papamuri , engari kei a matou etahi taapiri taapiri mo etahi atu ahuatanga e hiahia ana koe ki te hanga i a koe ake rōnaki.

@mixin gradient-bg($color: null) {
  background-color: $color;

  @if $enable-gradients {
    background-image: var(--#{$variable-prefix}gradient);
  }
}
// Horizontal gradient, from left to right
//
// Creates two color stops, start and end, by specifying a color and position for each color stop.
@mixin gradient-x($start-color: $gray-700, $end-color: $gray-800, $start-percent: 0%, $end-percent: 100%) {
  background-image: linear-gradient(to right, $start-color $start-percent, $end-color $end-percent);
}

// Vertical gradient, from top to bottom
//
// Creates two color stops, start and end, by specifying a color and position for each color stop.
@mixin gradient-y($start-color: $gray-700, $end-color: $gray-800, $start-percent: null, $end-percent: null) {
  background-image: linear-gradient(to bottom, $start-color $start-percent, $end-color $end-percent);
}

@mixin gradient-directional($start-color: $gray-700, $end-color: $gray-800, $deg: 45deg) {
  background-image: linear-gradient($deg, $start-color, $end-color);
}

@mixin gradient-x-three-colors($start-color: $blue, $mid-color: $purple, $color-stop: 50%, $end-color: $red) {
  background-image: linear-gradient(to right, $start-color, $mid-color $color-stop, $end-color);
}

@mixin gradient-y-three-colors($start-color: $blue, $mid-color: $purple, $color-stop: 50%, $end-color: $red) {
  background-image: linear-gradient($start-color, $mid-color $color-stop, $end-color);
}

@mixin gradient-radial($inner-color: $gray-700, $outer-color: $gray-800) {
  background-image: radial-gradient(circle, $inner-color, $outer-color);
}

@mixin gradient-striped($color: rgba($white, .15), $angle: 45deg) {
  background-image: linear-gradient($angle, $color 25%, transparent 25%, transparent 50%, $color 50%, $color 75%, transparent 75%, transparent);
}

API taputapu

Ko nga taputapu papamuri e whakaatuhia ana i roto i o maatau taputapu API i roto i scss/_utilities.scss. Akohia me pehea te whakamahi i nga taputapu API.

    "background-color": (
      property: background-color,
      class: bg,
      local-vars: (
        "bg-opacity": 1
      ),
      values: map-merge(
        $utilities-bg-colors,
        (
          "transparent": transparent
        )
      )
    ),
    "bg-opacity": (
      css-var: true,
      class: bg-opacity,
      values: (
        10: .1,
        25: .25,
        50: .5,
        75: .75,
        100: 1
      )
    ),