Example of selection pseudo class selector in CSS

Source: Internet
Author: User

:: The selection pseudo class selector is used for highlighting any part of the page user selection, including text in editable text fields.

This pseudo element can be applied to color, background-color, background (Background-color) and Text-shadow (Note: This property is not valid under IE at the current location) property. Setting other properties has no effect.


Firefox needs to add the-moz-attribute prefix;

Support browsers: Chrome,firefox (Gecko), Internet Explorer 9+,opera,safari

For example:

The code is as follows Copy Code

/* Draw any selected text yellow on red background * *
::-moz-selection {color:gold; background:red; }
:: Selection {color:gold; background:red; }

/* Draw selected text in a paragraph
p::-moz-selection {color:white; Background:black; }
p::selection {color:white; Background:black; }

A complete example:

The code is as follows Copy Code

<! DOCTYPE html>
<meta charset= "Utf-8"/>
<TITLE>CSS:: Selection pseudo class selector-web front-end development </title>
<meta name= "Author" content= "The Pier of Fools, www.css88.com"/>
<style>
p{text-shadow:2px 2px 5px #333333;}
P::-moz-selection{background: #000; color: #f00; text-shadow:2px 2px 5px #FFFF2E;}
P::selection{background: #000; color: #f00; text-shadow:2px 2px 5px #FFFF2E;}
</style>
<body>
<p> After you select this text, look at their text color and background colors, you can understand:: The role of selection. </p>
</body>

The effect is as follows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.