开发者

selecting/highlighting text with a different color

开发者 https://www.devze.com 2023-01-08 08:17 出处:网络
How开发者_如何学运维 do I change the colour of highlight/selection of text? The default is blue.

How开发者_如何学运维 do I change the colour of highlight/selection of text? The default is blue.

For example, if you highlight/select the text on this site, it is blue. But on css-tricks.com if the text is highlight/selected, it is orange peach.


::selection {
background: #ffb7b7; /* Safari */
}
::-moz-selection {
background: #ffb7b7; /* Firefox */
}

as it is explained in here:

http://css-tricks.com/overriding-the-default-text-selection-color-with-css/


It's a CSS3-only feature, that only Firefox and Safari have implemented so far (as far as I know).

::selection {
    background: #ffb7b7; /* Safari */
}
::-moz-selection {
    background: #ffb7b7; /* Firefox */
}


with JS you checkout where the selection is. then you remove it and change the css background-color of the selected text part in to orange ;-)


Why don't you read the css-tricks article on the subject: :-)

http://css-tricks.com/overriding-the-default-text-selection-color-with-css/


::selection {
    background: red;
}

::-moz-selection {
    background: red;
}

::-webkit-selection {
    background: red;
}

webkit selection fixed opera issue :)

0

精彩评论

暂无评论...
验证码 换一张
取 消