CSS3 新增了一个很有意思的属性 – mix-blend-mode ,其中 mix 和 blend 的中文意译均为混合,那么这个属性的作用直译过来就是混合混合模式,当然,我们我们通常称之为混合模式。
mix-blend-mode 用于多个不同标签间的混合模式
mix-blend-mode 描述了元素的内容应该与元素的直系父元素的内容和元素的背景如何混合。我们将 PS 中图层的概念替换为 HTML 中的元素。
CSS混合模式属性主要包括mix-blend-mode、isolation和background-blend-mode三个属性,
mix-blend-mode: normal; // 正常
mix-blend-mode: multiply; // 正片叠底
mix-blend-mode: screen; // 滤色
mix-blend-mode: overlay; // 叠加
mix-blend-mode: darken; // 变暗
mix-blend-mode: lighten; // 变亮
mix-blend-mode: color-dodge; // 颜色减淡
mix-blend-mode: color-burn; // 颜色加深
mix-blend-mode: hard-light; // 强光
mix-blend-mode: soft-light; // 柔光
mix-blend-mode: difference; // 差值
mix-blend-mode: exclusion; // 排除
mix-blend-mode: hue; // 色相
mix-blend-mode: saturation; // 饱和度
mix-blend-mode: color; // 颜色
mix-blend-mode: luminosity; // 亮度
mix-blend-mode: initial;
mix-blend-mode: inherit;
mix-blend-mode: unset;
按效果来分可以分为这几类
基础混合模式 normal 利用图层透明度和不透明度来控制与下面的图层混合
降暗混合模式 darken,multiply,color-burn 减色模式,滤掉图像中高亮色,从而达到图像变暗
加亮混合模式 screen,lighten,color-dodge 加色模式,滤掉图像中暗色,从而达到图像变亮
融合混合模式 overlay,soft-light,hard-light 用于不同程度的对上、下两图层的融合
变异混合模式 difference,exclusion,hard-light 用于制作各种变异的图层混合
色彩叠加混合模式 hue,saturation,color,luminosity 根据图层的色相,饱和度等基本属性,完成图层融合
demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
html,
body,
.app {
width: 100%;
height: 100%;
background: #666666;
padding: 0;
margin: 0;
position: relative;
}
img {
width: 200px;
height: 200px;
position: absolute;
top: 20%;
left: 35%;
mix-blend-mode: multiply; //是img的属性 可以把图片的纯色背景去掉
/* background-blend-mode: multiply; */ //是div属性
//也会与 transform 这个属性起冲突,使之mix-blend-mode不起作用
}
</style>
</head>
<body>
<div class="app">
<div>
<img src="./limahuacheng.png" alt="" />
</div>
</div>
</body>
</html>