selecting/highlighting text with a different color

早过忘川 提交于 2020-01-04 02:46:09

问题


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.


回答1:


::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/




回答2:


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 */
}



回答3:


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 ;-)




回答4:


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

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




回答5:


::selection {
    background: red;
}

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

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

webkit selection fixed opera issue :)



来源:https://stackoverflow.com/questions/3318229/selecting-highlighting-text-with-a-different-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!