javascript - 背景和文本混合模式的区别
问题描述
我试图理解混合模式,所以我创建了这个简单的例子:
.container {
background-color: gold;
position: relative;
display: flex;
justify-content: space-between;
padding: 20px;
}
.rect {
position: absolute;
left: 0;
top: 0;
bottom: 0;
background-color: blue;
width: 15%;
}
.text {
z-index: 1;
font-weight: bold;
font-size: 30px;
font-family: 'Arial';
}
.left {
color: white;
}
.right {
color: grey;
}
<div class="container">
<div class="rect" ></div>
<div class="text left">Left text</div>
<div class="text right">Right text</div>
</div>
有两种背景颜色(蓝色和金色)和两种应该始终可读的文本。我想要的是当背景为蓝色时有一个白色文本,当背景是黄色时有一个灰色文本(因为蓝色矩形可以增长)。
所以我尝试了:
.container {
background-color: gold;
position: relative;
display: flex;
justify-content: space-between;
padding: 20px;
}
.rect {
position: absolute;
left: 0;
top: 0;
bottom: 0;
background-color: blue;
width: 15%;
}
.text {
z-index: 1;
font-weight: bold;
font-size: 30px;
font-family: 'Arial';
mix-blend-mode: difference;
}
.left {
color: white;
}
.right {
color: dimgrey;
}
<div class="container">
<div class="rect" ></div>
<div class="text left">Left text</div>
<div class="text right">Right text</div>
</div>
这与我想要的相似,但不完全一样。你有想法吗?
解决方案
推荐阅读
- amazon-web-services - AWS CloudFormation:无法将安全组附加到 ElasticBeanstalk 的实例
- gremlin - 如何按父母分组并在gremlin中收集孩子的所有属性值?
- python - 使用 Matplotlib 绘制 y 坐标为字符串的标记?
- nginx - 即使我在 Nginx 中打开了 SSL,它也不起作用?
- python - 将图例添加到具有二进制数据的 numpy 数组的 matplotlib 图中
- javascript - 在 util.promisify 请求迭代失败后继续 .map 循环(异步等待)
- c# - 如何使用c#杀死除特定进程之外的所有进程
- reactjs - 使用 Jest 或 Mocha 进行测试时导入反应模块时出错
- javascript - Javascript - 将 API 调用中的数据存储到对象中
- apache-spark - 在 Spark SQL 中优化 Theta 连接