Webkit : Css 文本选择样式不能使背景变白?

Webkit : Css text selection styling can not make background white?

因此,文本选择通过 ::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/

上的此片段

可能是浏览器的问题。

试试这个:

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.

这是打印的结果:

好的,所以按照 this question 我找到了答案:

For some reason Chrome forces it to be semi-transparent. However, you can get around this by setting the background using rgba. I have set the alpha value to be just 0.01 less than 1.

::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.