background-blend-mode

概述

background-blend-mode CSS 属性定义该元素的背景图片,以及背景色如何混合。

混合模式应该按background-image CSS 属性同样的顺序定义。如果混合模式数量与背景图像的数量不相等,它会被截取至相等的数量。

初始值normal
适用元素All elements. In SVG, it applies to container elements, graphics elements, and graphics referencing elements.. It also applies to ::first-letter and ::first-line.
是否是继承属性
计算值as specified
Animation typeNot animatable

语法

Formal syntax:  
background-blend-mode = 
<mix-blend-mode>#

/* 单值 */
background-blend-mode: normal;

/* 双值,每个背景一个值 */
background-blend-mode: darken, luminosity;

background-blend-mode: initial;
background-blend-mode: inherit;
background-blend-mode: unset;

<blend-mode>

一个定义混合的模式,可以有多个值,用逗号间隔。

示例

css
#div {
  width: 300px;
  height: 300px;
  background: url("br.png"), url("tr.png");
  background-blend-mode: screen;
}
js
document.getElementById("select").onchange = function (event) {
  document.getElementById("div").style.backgroundBlendMode =
    document.getElementById("select").selectedOptions[0].innerHTML;
};
console.log(document.getElementById("div"));

规范

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

浏览器兼容性

BCD tables only load in the browser

参见