background-blend-mode

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流浏览器均已支持。

background-blend-mode CSS 属性设置元素的背景图像如何相互融合以及如何与元素的背景颜色融合。

试一试

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

混合模式的定义顺序应与 background-image 属性的定义顺序相同。如果混合模式列表和背景图像列表的长度不相等,则会重复和/或截断,直到长度匹配。

语法

css
/* One value */
background-blend-mode: normal;

/* Two values, one per background */
background-blend-mode: darken, luminosity;

/* Global values */
background-blend-mode: inherit;
background-blend-mode: initial;
background-blend-mode: revert;
background-blend-mode: revert-layer;
background-blend-mode: unset;

<blend-mode>

要应用的混合模式。可以有多个值,用逗号分隔。

正式定义

初始值normal
应用于所有元素。在 SVG 中,它适用于容器元素、图形元素和图形引用元素。它也适用于 ::first-letter::first-line
继承性
计算值同指定值
动画类型不可动画化

正式语法

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

示例

基本示例

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

尝试不同的混合模式

规范

规范
Compositing and Blending Level 2
# background-blend-mode

浏览器兼容性

另见