字体随背景颜色改变
需要用到的css属性:mix-blend-mode
参考链接:
https://developer.mozilla.org/zh-CN/docs/Web/CSS/mix-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; //复原
要点:
若想实现空白部分字体显示颜色A,有背景部分字体显示白色,则需要一个颜色A的纯色的背景
(参考样例一,其中的纯色背景为#blackbg)
样例:
----------------------------样例一-----------------------------------
css 部分:
/* A white bottom layer */
#whitebg {
position: absolute;
width: 400px;
height: 200px;
background: white;
z-index: 1
}
/* A black layer on top of the white bottom layer */
#blackbg {
position: absolute;
width: 200px;
height: 200px;
background-color: black;
z-index: 2
}
/* A red DIV over the scene with the blend-mode set to 'screen' */
#makered {
position: absolute;
width: 400px;
height: 200px;
background-color: red;
background-size: auto 100%;
mix-blend-mode: screen;
z-index: 4
}
span {
position: absolute;
font-family: Arial, Helvetica;
font-size: 100px;
mix-blend-mode: difference;
color: white;
z-index: 3
}
html部分:
<div id="whitebg"></div>
<div id="blackbg"></div>
<div id="makered"></div>
<span>testtest</span>
--------------------------------样例二--------------------------------------
css 部分:
.circle {
width: 80px;
height: 80px;
border-radius: 50%;
mix-blend-mode: screen;
position: absolute;
}
.circle-1 {
background: red;
}
.circle-2 {
background: lightgreen;
left: 40px;
}
.circle-3 {
background: blue;
left: 20px;
top: 40px;
}
.isolate {
isolation: isolate;
position: relative;
}
html部分:
<div class="isolate">
<div class="circle circle-1"></div>
<div class="circle circle-2"></div>
<div class="circle circle-3"></div>
</div>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix