You need to enable JavaScript to run this app. 如何单独修改被上层形状元素遮挡的交叉文本颜色
优惠活动
大模型
产品
解决方案
定价
更多

如何单独修改被上层形状元素遮挡的交叉文本颜色

文本与形状交叉区域自定义改色实现

核心需求

  • 普通HTML文本(如<h1>标签承载的内容)被任意形状元素遮挡时,仅修改文本与形状交叉部分的颜色,非交叉区域保留文本默认设置的颜色
  • 场景适配:遮挡源既可以是独立的HTML形状元素,也可以是容器配置的背景图形状
  • 自定义能力:交叉区域的颜色支持任意值配置,不依赖调整元素透明度实现视觉混合效果

测试代码

以下为测试阶段编写的完整代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    text-transform: uppercase;
}

body {
    font-family: sans-serif;
    font-size: 6vw;
    display: flex;
    height: 100vh;
    justify-content: center;
    align-items: center;
}

#con {
    position: relative;
}

h1:not(#cloned) {
    color: blue;
    position: absolute;
    top: 0;
    left: 0;
}

#cloned {
    color: transparent;
}

#shape {
    display: inline-block;
    height: 18.7vw;
    width: 18.7vw;
    background-color: red;
    border-radius: 50%;
    position: absolute;
    top: 5%;
    right: 10%;
    opacity: 50%;
}
    </style>
</head>
<body>
    <div id="con">
        <h1>this is<br>awesome</h1>
        <h1 id="cloned">this is<br>AWESOME</h1>
        <div id="shape"></div>
    </div>
</body>
</html>

内容的提问来源于stack exchange,提问作者Faisal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.08 08:15:02