css3 正片叠加
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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通