CSS Properties-the difference between pseudo-classes and pseudo-elements

Source: Internet
Author: User

Pseudo-classes and pseudo-elements are independent of the document structure. The way they get the elements is not based on the element characteristics of the ID, class, attribute, but on the element that is in a special state (pseudo-Class), or the element's special content (pseudo-element). The difference is summarized as follows:

① does not have the same wording:

css3To differentiate between the two, the pseudo-class is explicitly represented by a colon, and the pseudo-element is represented by two colons.
:Pseudo-classes::Pseudo-elements


The ② function is not the same:

CSS Pseudo-Class (pseudo-classes): Used to add special effects to certain selectors, that is, to add special effects (usually dynamic effects) on the basis of the current static style of the element . So when an element reaches a certain state, it may get a pseudo-class style, and when the state changes, it loses the style.

Property Describe
: Active Add a style to the element that is activated
: Focus Add a style to an element that has keyboard input focus
: hover Add a style to an element when the mouse hovers over the element
: Link Add a style to a link that is not visited
: Visited Add a style to a link that has been visited
: First-child Add a style to the first child element of an element
: lang Add a style to an element with the specified Lang property

remark: In the  CSS definition, the same element: hover must be in: Link,: Visited before it takes effect: active must be in: hover before it takes effect. 

CSS Pseudo-elements (pseudo-elements): Used to set special effects to certain selectors, is to set and manipulate specific content in the element , the operation level is deeper than pseudo-class, so the dynamic is worse than pseudo-class.

description
:first-letter add a special style to the first letter of the text
:first-line add a special style to the first line of text
:before add content before element
:after add content after element



CSS Properties-the difference between pseudo-classes and pseudo-elements

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.