【发布时间】:2020-07-29 11:16:04
【问题描述】:
我将以下 CSS 应用于 <html> 标签:filter: invert(1);
即使background-color 的元素,所有元素都会反转,(Chrome v80)
一旦我在 Safari iOS 13 / Safari MacOS 上尝试相同的操作,除了 的 background-color
我正在运行的所有浏览器都支持 CSS 过滤器属性:
https://caniuse.com/#feat=mdn-css_properties_filter。
有人能解释一下这种行为吗?
html {
filter: invert(1);
/* this background-color does not change on ios+other browsers */
background: #fff;
padding: 50px;
}
body {
background-color: #0000ff;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.text {
text-align: center;
color: red;
}
<div class="text">
If it works: color should not be red, background should not be blue
</div>
【问题讨论】:
-
尝试添加
html{background:#fff} -
@TemaniAfif 我已经更新了 sn-p,同样的问题没有倒过来。
-
很有趣,same discrepancy happens with
opacity+background-color,FF 不会让不透明度影响 html 的背景,而 Chrome 在 iframe 中不会影响,但在页面在自己的窗口中运行时默认为白色。并且 Safari 具有 Chrome 的逆行为(这似乎更符合 IMM 逻辑)。 @TemaniAfif 知道规范对此有什么看法吗? -
为什么不用
:root这个用js切换背景呢?如果我没记错的话,这通常就是现在创建黑暗主题等的方式。 -
是的。但我正在考虑应用实际的颜色反转应用