Home  >  Article  >  Web Front-end  >  CSS3::selection selector_html/css_WEB-ITnose

CSS3::selection selector_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:39:131016browse

I have seen that the color and background color of selected content on some websites are not the usual blue and white. I was interested in checking it out today. It turned out to be a very simple usage of CSS3 selector::selection.

Example above:

<style>        .selectColor::selection{color:#fff;background:pink;}        .selectColor::-moz-selection{color:#fff;background:pink;}        .selectColor::-webkit-selection{color:#fff;background:pink;}</style><body>    <p>普通文本,不设置::section,选中时文本的颜色为白色,背景色为蓝色</p>    <p class="selectColor">选择文本的颜色为白色,背景色为粉色</p></body>

Only a few CSS properties can be applied to the ::selection selector: color, background, cursor and outline .

Browser support:

The ::selection selector is supported in IE9, Opera, Google Chrome and Safari.

Firefox supports alternative ::-moz-selection.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn