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 typediscrete

语法

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>

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

示例

<select id="select">     <option>normal</option>     <option>multiply</option>     <option selected>screen</option>     <option>overlay</option>     <option>darken</option>     <option>lighten</option>     <option>color-dodge</option>     <option>color-burn</option>     <option>hard-light</option>     <option>soft-light</option>     <option>difference</option>     <option>exclusion</option>     <option>hue</option>     <option>saturation</option>     <option>color</option>     <option>luminosity</option> </select>
#div {
    width: 300px;
    height: 300px;
    background: url('https://mdn.mozillademos.org/files/8543/br.png'),url('https://mdn.mozillademos.org/files/8545/tr.png');
    background-blend-mode: screen;
}
document.getElementById("select").onchange = function(event) {
    document.getElementById("div").style.backgroundBlendMode = document.getElementById("select").selectedOptions[0].innerHTML;
}
console.log(document.getElementById('div'));

规范

规范 状态 备注
Compositing and Blending Level 1
background-blend-mode
Candidate Recommendation 首次定义

浏览器兼容性

BCD tables only load in the browser

参见