Pseudo-class selectors and pseudo-elements in CSS

Source: Internet
Author: User

1. Pseudo-Class selectors

In CSS, the most commonly used pseudo-class selectors are several selectors that are used on a (anchor) element, and they are used in the following ways:

A:link{color: #FF0000; Text-decoration:none}

A:visited{color: #FF0000; Text-decoration:none}

A:hover{color: #FF0000; Text-decoration:none}

A:active{color: #FF0000; Text-decoration:none}

2. Pseudo element Selector

The pseudo-element selector is not a selector for a real element, but a selector for a pseudo-element that has already been defined in the CSS, with the following four pseudo-element selectors in the CSS:

(1) first-line pseudo-element Selector

<style type=text/css>

P:first-line{color: #0000FF};

</style>

(2) First-letter pseudo-element Selector

Use styles for the first letter of text in an element (European and American text) or the first word (Chinese and Japanese characters).

<style type=text/css>

P:first-letter{color: #0000FF};

</style>

(3) before pseudo-element selector

The before pseudo-element selector has some content inserted before an element, using the following method:

Element: before{

Content: ""

}

<style type= "Text/css" >

Li:before{content: "Hello"}

</style>

(4) after pseudo element selector

<style type= "Text/css" >

li:after{

Content: "Hello";

font-size:12px;

color:red;

}

</style>

Pseudo-class selectors and pseudo-elements in CSS

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.