【发布时间】:2023-03-17 14:24:01
【问题描述】:
如果我有一个普通文本(例如<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>
【问题讨论】:
-
你应该至少添加一部分代码
-
了解混合混合模式
-
我已经添加了我的代码!我读到了
mix-blend-mode并没有找到与选择我自己的颜色相关的东西...... -
可以介绍一点Javascript吗? (不是说你是否可以或不能使用混合混合模式,但获得任何你想要的颜色可能会很棘手)。