Pseudo-classes and pseudo-elements in detail

The difference between pseudo-classes and pseudo-elements in CSS1 and CSS2 is rather vague. CSS3 makes a relatively clear concept of these two concepts, and clearly distinguishes them in terms of syntax.

The difference between pseudo-classes and pseudo-elements is whether new elements are created.

1. Pseudo class

What are pseudo classes?

Pseudo-classes are used to define special states of elements

For example. It can have the following effects

  • Style the element when the mouse is hovering over it
  • Styles for clicked and unclicked links
  • Sets the style for an element to get focus

The following are several commonly used pseudo-classes: the effect of pseudo-classes can be achieved by adding actual classes

2. Pseudo elements

The way of writing in css2 is: before, and the way of writing in css3 is:: before.

The effect of pseudo-elements can be achieved by adding actual elements

Note:
Pseudo-classes can only use ":"
and pseudo-elements can use both ":" and "::"
because pseudo-classes are similar to adding classes, so there can be multiple ones, and pseudo-elements can only be used in a selector Can appear once, and only at the end

 

Guess you like

Origin blog.csdn.net/m0_37756431/article/details/123506278