html - 使用 CSS 将文本颜色设置为红色背景上的白色和白色背景上的黑色文本颜色

我需要一个 CSS 样式,当背景为红色时文本颜色为白色,背景为白色时文本颜色为黑色。

我的红色背景有以下颜色:#d6002e

我将这个 CSS 添加到我的文本中:

mix-blend-mode: difference;
color: #29FBFF;  // Inverted color of my red

现在看起来像这样:

我的文本得到了反色的背景,这不是我想要的。

最佳答案

我觉得这应该可以解决问题

.my-red-bg {
    background: #d6002e;
    color: white
  }


.my-black-bg {
    background: black;
    color: white
 }

https://stackoverflow.com/questions/69581974/

相关文章:

html - 在新标签页中打开 PDF - Blazor

next.js - 如何在 Next.js 中排除单个路由中的尾部斜线?

google-cloud-platform - 将 PHP crypt MD5 密码导入 Googl

javascript - 无法从 'localStorage' 读取 'Window' 属性 : A

swiftui - 如何在 iOS 15 中使用 SwiftUI 在特定 View 中隐藏 TabB

node.js - SassError : Can't find stylesheet to imp

javascript - 如何将 HTMLElement 转换为 JSX.Element

sql - 传递大的逗号分隔值时,使用 Custom TABLE TYPE 作为参数而不是 SQL

java - ClassLoader不加载内部类

python - 在 Python@3.10 上安装 cytoolz 时出现问题