简体   繁体   中英

How to change the color of selected text in the HTML page?

I want to know how can I change the highlight color of selected text?

Here is by default?

在此输入图像描述

And I want something like this:

在此输入图像描述

It should be noted I'm not talking about font-family . I just want to change the highlight color .., How can I do that?

::selection {
  background: #ffb7b7;
}
::-moz-selection {
  background: #ffb7b7;
}

Also for more information you can see this .

Example :

 p::selection { background: #FEAA90; } p::-moz-selection { background: #FEAA90; } 
 <p>Click on "Run code snippet" and select this text.</p> 

Support : http://caniuse.com/#feat=css-selection

我可以使用::选择吗?

You can do by ::selection Pseudo-element

For example:

::selection {
    color: red;
    background: #FEAA90;
}

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