background-blend-mode

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Thuộc tính CSS background-blend-mode xác định cách các ảnh nền của một phần tử được pha trộn với nhau và với màu nền của phần tử đó.

Các chế độ pha trộn phải được khai báo theo cùng thứ tự như thuộc tính background-image. Nếu độ dài danh sách chế độ pha trộn và ảnh nền không bằng nhau, danh sách sẽ được lặp lại và/hoặc cắt bớt cho đến khi độ dài khớp nhau.

Try it

background-blend-mode: normal;
background-blend-mode: multiply;
background-blend-mode: hard-light;
background-blend-mode: difference;
<section class="default-example" id="default-example">
  <div class="example-container">
    <div class="transition-all" id="example-element"></div>
  </div>
</section>
#example-element {
  background-color: green;
  background-image: url("/shared-assets/images/examples/balloon.jpg");
  width: 250px;
  height: 305px;
}

Cú pháp

css
/* Một giá trị */
background-blend-mode: normal;

/* Hai giá trị, một cho mỗi ảnh nền */
background-blend-mode: darken, luminosity;

/* Giá trị toàn cục */
background-blend-mode: inherit;
background-blend-mode: initial;
background-blend-mode: revert;
background-blend-mode: revert-layer;
background-blend-mode: unset;

Giá trị

<blend-mode>

Chế độ pha trộn được áp dụng. Có thể có nhiều giá trị, phân cách bằng dấu phẩy.

Định nghĩa hình thức

Initial valuenormal
Applies toAll elements. In SVG, it applies to container elements, graphics elements, and graphics referencing elements.. It also applies to ::first-letter and ::first-line.
Inheritedno
Computed valueas specified
Animation typeNot animatable

Cú pháp hình thức

background-blend-mode = 
<'mix-blend-mode'>#

<mix-blend-mode> =
<blend-mode> |
plus-lighter

<blend-mode> =
normal |
darken |
multiply |
color-burn |
lighten |
screen |
color-dodge |
overlay |
soft-light |
hard-light |
difference |
exclusion |
hue |
saturation |
color |
luminosity

Ví dụ

Ví dụ cơ bản

css
.item {
  width: 300px;
  height: 300px;
  background: url("image1.png"), url("image2.png");
  background-blend-mode: screen;
}

Thử các chế độ pha trộn khác nhau

Đặc tả

Specification
Compositing and Blending Module Level 2
# background-blend-mode

Tương thích trình duyệt

Xem thêm