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

前端之家收集整理的这篇文章主要介绍了Webkit:Css文本选择样式不能使背景变白?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
因此,文本选择可以通过:: 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)@H_301_7@

@H_301_7@

另请参阅https://jsfiddle.net/duk3/hzodm1sh/的这个片段@H_301_7@

解决方法

好吧,在 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.@H_301_7@

::selection { color: black;  background: rgba(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.

猜你在找的CSS相关文章