Just run into something surprising. If you do this:
footer::selection {
color: white;
}
...it also removes the browser-default background-color for the highlighted text. It behaves as if you had also set background-color: transparent
. (See demo below.)
Question: How can I retain or restore the system default text selection background-colour
when setting a custom ::selection
color
?
(This answer lists various selection background colours used on different systems. But I don't just want to choose one, I want it to just be whatever the default is for the current system.)
Demo:
body {
background: navy;
color: gray;
}
p.custom::selection {
color: white;
}
<p>Regular paragraph</p>
<p class="custom">Paragraph with text color changed in ::selection</p>