Summary of pseudo-elements and pseudo-elements of CSS Common properties

Source: Internet
Author: User
We talked about the ID selector and class selector, and their differences and relationships, and let's explore the magical categories and pseudo-elements.

In fact, I used to pseudo-class and pseudo-elements are also confused, and now decided to peel off its mysterious cloak, first of all, what is pseudo-class? What is a pseudo-element?

Understanding of pseudo-classes and pseudo-elements:

Official explanation:

The pseudo-class is initially used to represent the dynamic state of some elements, typically the various states of the links (link, active, hover, visited) that are commonly used, and then the CSS2 standard
Extends its conceptual scope to a "ghost" classification that is logically present but is not identified in the document tree.

Pseudo-elements represent the child elements of an element that, although logically present, do not actually exist in the document tree, such as after, before, etc., which we normally use.

His superficial understanding is that the pseudo-class is a class that does not need to be identified, the pseudo-element is an element, but does not exist with the document tree.

About usage: A pseudo-class is preceded by a colon, and a pseudo-element is preceded by two colons. E:first-child pseudo-class, e::first-line pseudo-element. This is the latest CSS3 standard, but in CSS2
About after and before all use a colon, and here you need to pay attention. And CSS3 also extended a lot of pseudo-class, here does not mention, interested in their own can go to check the information.

Common applications:
Pseudo-Class:
1.a link Style <a href= "#" > Click link </a> a:hover{color:red} mouse hover font turns red.

2. Interlaced Color <ul><li>1</li><li>2</li><li>3</li><li>4</li></ Ul> ul Li:nth-child (even) {background-color: #ccc} or UL Li:nth-chilid (2): {background-clolor: #ccc}

Pseudo elements:
Clear float:
. clear{zoom:1}
. Clear:after{display:block;content: '; clear:both;}

As for pseudo-classes and pseudo-elements, there are many interesting effects on pseudo-classes and pseudo-elements.

Related Article

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.