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,实现了图片和背景色的正片叠底效果。

相关推荐
阿苟1 分钟前
nginx部署踩坑
前端·后端
小林攻城狮3 分钟前
pdfmake 生成平铺式水印:核心方法与优化
前端
search76 分钟前
前端设计:CRG 2--CDC检查
前端·芯片设计
松涛和鸣9 分钟前
DAY33 Linux Thread Synchronization and Mutual Exclusion
linux·运维·服务器·前端·数据结构·哈希算法
逛逛GitHub16 分钟前
我把公众号文章导入了腾讯 ima,可以对话找开源项目了。
前端·github
lionliu051927 分钟前
JavaScript 变量声明最佳实践
前端·javascript·vue.js
源去_云走30 分钟前
自建 Iconfy API 服务:解决国内访问不稳定问题
前端·容器·npm·node.js
AAA阿giao33 分钟前
从零开始学 React:用搭积木的方式构建你的第一个网页!
前端·javascript·学习·react.js·前端框架·vite·jsx
遇到困难睡大觉哈哈35 分钟前
Harmony OS Web 组件:如何在新窗口中打开网页(实战分享)
前端·华为·harmonyos
你脸上有BUG1 小时前
【工程化】前端打包时间优化
前端