css 实现背景图和背景色正片叠底

要实现背景图和背景色的正片叠底效果,可以使用CSS的mix-blend-mode属性。mix-blend-mode属性定义了元素的内容与其背景层如何混合。当设置为multiply时,可以实现正片叠底效果

案例

css 复制代码
.style {
    background: url(https://xxx.png) no-repeat;
    background-size: 100% 100%;
    background-blend-mode: multiply;  /*正片叠底 */
}

混合模式

css 复制代码
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;           //复原

图片底层混合

html 复制代码
<div>
    <img src="">
</div>
css 复制代码
div {
    background: #f6f6f6         //添加背景灰色
}
div img {
    mix-blend-mode: multiply;   //正片叠底
}

在这个示例中,我们创建了一个包含背景颜色和图片。通过将覆盖层的mix-blend-mode属性设置为multiply,实现了图片和背景色的正片叠底效果。

相关推荐
mCell12 小时前
GSAP ScrollTrigger 详解
前端·javascript·动效
gnip12 小时前
Node.js 子进程:child_process
前端·javascript
excel15 小时前
为什么在 Three.js 中平面能产生“起伏效果”?
前端
excel16 小时前
Node.js 断言与测试框架示例对比
前端
天蓝色的鱼鱼18 小时前
前端开发者的组件设计之痛:为什么我的组件总是难以维护?
前端·react.js
codingandsleeping18 小时前
使用orval自动拉取swagger文档并生成ts接口
前端·javascript
石金龙19 小时前
[译] Composition in CSS
前端·css
白水清风19 小时前
微前端学习记录(qiankun、wujie、micro-app)
前端·javascript·前端工程化
Ticnix19 小时前
函数封装实现Echarts多表渲染/叠加渲染
前端·echarts
用户221520442780019 小时前
new、原型和原型链浅析
前端·javascript