Webkit: Css text selection style can't do white background?

Thus, the stylist made the selection through the pseudo-element :: selection in order to override the default selection color for the browser. But for me it seems that the white color of the highlight is forbidden in favor of a grayish, opaque color.

::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.
Run codeHide result

Why doesn't this create a completely white background? Instead, it shows a gray background (# 989898)

Css selection doesn't accept white background

Also see this snippet at https://jsfiddle.net/duk3/hzodm1sh/

+4
source share
3 answers

So, following this question , I found the answer:

- Chrome . , rgba. 0,01 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.
Hide result
+3

, .

:

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.
Hide result

:

...

+1

You should try:

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

::selection {
    color:black;
    background: white;
}
body {
    background: black;
    color: white;
}
So selecting me is supposed to invert the text and background colors.
Run codeHide result
0
source

Source: https://habr.com/ru/post/1609275/


All Articles