Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is this css selector for ::selection not working?

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 class="blog">
<p class="text-condensed-light text-15-rem mt-20">This text should be red when selected.</p>
</body>

Any help appreciated.

CODEPEN

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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 class="text-condensed-light text-15-rem mt-20">This text should be red when selected.</p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading