【问题标题】:Webkit : Css text selection styling can not make background white?Webkit:CSS文本选择样式不能使背景变白?
【发布时间】:2015-09-28 10:26:13
【问题描述】:

所以文本选择通过 ::selection 伪元素进行样式化,以覆盖浏览器的默认选择颜色。但对我来说,白色作为选择背景颜色似乎是被禁止的,而是采用灰色、不透明的颜色。

::selection      { color: black;  background: white; }
::-moz-selection { color: black;  background: white; }

body {
    background: black;
    color: white;
}
So selecting me is supposed to invert the text and background colors. But the selected text background color is not white, but grey.

为什么这创建一个完美的白色背景?相反,它显示灰色背景 (#989898)

https://jsfiddle.net/duk3/hzodm1sh/上也可以看到这个sn-p

【问题讨论】:

  • 你在什么浏览器上得到这个结果?
  • 这发生在 Chrome 和 Safari 中 - 当前版本仍然存在

标签: css webkit selection styling


【解决方案1】:

好的,关注this question我找到了答案:

由于某种原因,Chrome 强制它是半透明的。然而,你 可以通过使用 rgba 设置背景来解决这个问题。我已经设定 alpha 值仅比 1 小 0.01。

::selection { color: black;  background: rgba(255, 255, 255, 0.996);
; }

body {
    background: black;
    color: white;
}
Selecting me DOES invert the text and background colors. Well, almost, but it looks like perfect white.

【讨论】:

    【解决方案2】:

    可能是浏览器特有的问题。

    试试这个:

    Fiddle

    ::selection {
        color: black;
        background: white;
    }
    body {
        background: black;
        color: white;
    }
    ::-moz-selection {
        color: black;
        background: white;
    }
    So selecting me is supposed to invert the text and background colors.

    这是打印结果:

    【讨论】:

    • 您正在链接到一个红色背景颜色选择示例。我也看到它是红色的,我的问题特别涉及白色
    • 已更正@Romainpetit
    • 好的,我编辑了 moz 前缀属性,所以我们现在使用相同的代码。您认为选择背景是纯白色还是灰色?
    • 选中后,我看到白色背景上的黑色字母。我将在答案中添加打印件
    • 感谢chaipa,所以这确实必须是特定于环境的浏览器。我要深入研究这个
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 2020-01-13
    • 1970-01-01
    • 2014-03-27
    • 2013-01-16
    相关资源
    最近更新 更多