CSS class, Pseudo-class and pseudo-element differences

Source: Internet
Author: User

The class in CSS is designed to facilitate filtering (that is, selecting) elements to add styles to such elements, which are defined in the HTML document tree.

But this is not enough in some cases, such as the user's interaction (hover, activation, etc.) can cause the state of the element to change, class is powerless for these dynamic changes.


For this reason, CSS introduces the concept of Pseudo-class (Pseudo-class) to support the ability to filter elements based on information other than the document tree.

Pseudo-Class is an abstract class, essentially a class, so its main function is to select the element and then set the specific style.

The definition of a pseudo-class uses: a single colon plus a name , such as Mydiv:hover.

A pseudo-Class selection object may change as the user operates the document, such as when a user deletes certain nodes, affecting the selection of the child element (Nth-child) pseudo-class.

Pseudo-Class selection elements are based not on names, attributes, or content, but on characteristics (such as State or order). (: Except Lang)


Pseudo-elements (pseudo-element) are another concept designed with pseudo-class intent to support formatting based on information other than the document tree.

A pseudo-element is essentially an element, but it generally needs to be attached to an existing element as a "part" or "supplement" to that element. For example:: First-line or:: After.

The new pseudo-element syntax introduced in the CSS2.1 specification is a double colon::, but for compatibility with historical versions, some of the previously introduced pseudo-elements can still use the single colon syntax.

Unlike pseudo-classes used to filter elements , pseudo-elements are used to filter content or create supplemental content, wrap a virtual container outside of the content, and then apply a specific style.

We can apply pseudo-classes on pseudo-elements.


Here is an online example that can intuitively understand how they are used: http://wow.techbrood.com/fiddle/15719


To learn more about pseudo-classes, the use of pseudo-elements, instances, and differences.

Please refer to the reading online tutorial: http://techbrood.com/Guide/h5b2a?p=css-pseudo-elements


by Iefreer

CSS class, Pseudo-class and pseudo-element differences

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.