简体   繁体   中英

Why does *::selection not give you the correct colour?

I have Googled this but can't find any info on it.

Say you set your page highlight colour to a nice orange :

*::selection {
     background: #C44610;
 }

Why, when you highlight your page, does the background show as red , I swabbed this colour in photoshop and it gives me a hex value of #c24432 which is way off the orange I selected.

I have tested this on Chrome. In firefox I can't get the selection to work at all, it just gives me the default colour.

Any thoughts?

For example you can edit this code:

::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }

Don't need the *

Also will need the ::-moz-selection {} for Firefox

BTW, you shoulkd consider that since the selection color is a bit transparent, it changes depending on the background...

Greetings from Argentina

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM