Home > Web Front-end > CSS Tutorial > Summary of css common attributes pseudo-elements and pseudo-elements

Summary of css common attributes pseudo-elements and pseudo-elements

高洛峰
Release: 2017-03-04 17:07:29
Original
2025 people have browsed it

In the previous times, we talked about the id selector and class selector respectively, as well as their differences and connections. Let’s explore the magical classes and pseudo-elements together.

In fact, I was confused about pseudo-classes and pseudo-elements before. Now I decided to peel off its mysterious coat. First of all, what is a pseudo-class? What are pseudo elements?

Understanding of pseudo-classes and pseudo-elements:

Official explanation:

Pseudo-classes were initially used to represent the dynamic status of some elements, typically commonly used links. The various states (link, active, hover, visited), then the CSS2 standard
expanded its conceptual scope, making it all "ghost" categories that exist logically but have no identity in the document tree.

Pseudo elements represent the sub-elements of a certain element. Although this sub-element exists logically, it does not actually exist in the document tree, such as the after, before, etc. we usually use.

My rough understanding is that a pseudo-class is a class that does not need to be identified, and a pseudo-element is an element, but it does not exist in the document tree.

About usage: Pseudo-classes are preceded by a colon, and pseudo-elements are preceded by two colons. E:first-child pseudo-class, E::first-line pseudo-element. This is the latest CSS3 standard, but in CSS2
uses a colon for both after and before, so everyone needs to pay attention here. Moreover, CSS3 has also expanded a lot of pseudo-classes, which I won’t mention here. If you are interested, you can check the information yourself.

Common applications:
Pseudo class:
1.a link styleclick link a:hover{color:red} mouse hover The font turns red.

2. Interlaced color change

  • 1
  • 2
  • 3
  • 4
ul li:nth-child(even){background-color:#ccc} or ul li:nth-chilid(2):{background-clolor:#ccc}

pseudo-element:
Clean up floats:
.clear{zoom:1}
.clear:after{display:block;content:'';clear:both;}

About pseudo-classes and pseudo-elements , that’s it for now. Regarding pseudo-classes and pseudo-elements, many interesting effects can be achieved.

For more articles related to summary of common css attributes pseudo-elements and pseudo-elements, please pay attention to the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template