字体随背景颜色改变

需要用到的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>
posted @   九月旅人  阅读(13)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· 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
点击右上角即可分享
微信分享提示