【问题标题】:Set text color to white on red background and black text color on white background with CSS使用 CSS 将文本颜色设置为红色背景上的白色和白色背景上的黑色文本颜色
【发布时间】:2021-12-03 11:54:35
【问题描述】:

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

我的红色背景颜色如下:#d6002e

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

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

现在看起来像这样:

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

【问题讨论】:

标签: html css colors background-color


【解决方案1】:

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

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


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

【讨论】:

    猜你喜欢
    • 2017-09-04
    • 2010-11-22
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多