Home  >  Article  >  Web Front-end  >  What are css pseudo-classes

What are css pseudo-classes

藏色散人
藏色散人Original
2021-04-09 15:03:362025browse

CSS pseudo-classes are used to add some special effects of selectors. They are used to add corresponding styles to existing elements when they are in a certain state. This state changes dynamically based on user behavior.

What are css pseudo-classes

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

For example: when the user hovers over a specified element, you can use :hover to describe the state of this element. Although it is similar to general CSS and can add styles to existing elements, it can only be in Styles can be added to elements only when the DOM tree cannot describe them, so they are called pseudo-classes.

It feels like pseudo-classes can be dynamic, and an element can gain or lose a pseudo-class when the user interacts with the document. The exceptions are ":first-child" which can be inferred from the document tree, and ":lang" which is also inferred from the document tree in some cases.

It can be seen that its function is somewhat similar to class, but it is based on abstraction outside of the document, so it is called a pseudo class.

Pseudo classes include: :first-child, :link:, vistited, :hover:, :active, :focus, :lang, :right, :left, :first

What is Pseudo class?

is the built-in class of css. The css itself gives it some features and functions. That is, you don’t need class=... or id=..., you can use it directly. Of course, you can also You can change some of its attributes, such as: a:link{color:#FF0000;}

Many CSS suggestions are not supported by browsers, but there are four pseudo-classes that can be safely used on hyperlinks. .

  • :link is used for unvisited connections.

  • : visited is used on already visited connections.

  • : active is used on connections that have received focus (for example, been clicked).

  • :hover is used for the connection over which the mouse cursor is placed.

【Recommended learning: css video tutorial

The above is the detailed content of What are css pseudo-classes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn