Home > Net >  Why is this css selector for ::selection not working?
Why is this css selector for ::selection not working?

Time:08-30

Hi I want to give the p tag selection styles, but it doesn't work, any idea why?

body.blog p::selection,
body.blog p::-moz-selection {
 color: red;
}
<body >
<p >This text should be red when selected.</p>
</body>

Any help appreciated.

CODEPEN

CodePudding user response:

When a browser encounters a selector it does not support it ignores the whole rule.

So separate the rules.

p::-moz-selection {
  color: red;
}

p::selection {
  color: red;
}
<p >This text should be red when selected.</p>

  • Related