CSS pseudo-selector learning pseudo-element selector analysis
In the previous article "What is a hierarchical selector in CSS? how to use? ", we learned about 4 types of hierarchical selectors. Let's talk about pseudo-selectors. They provide more complex functions, but do not directly correspond to the elements that HTML documents should have. There are two main types of pseudo-selectors: pseudo-elements and pseudo-classes. Let’s first talk about pseudo-element selectors in detail.
Pseudo-element selector
Pseudo-element selector in CSS is to add keywords to the specified CSS selector. Used to describe the styling of a specific part of a specified element. [Recommended learning: css video tutorial]
Through pseudo-elements, developers can define styles for specific parts of the selected element without using the ID or class attributes of the element. For example, through pseudo-elements you can set the style of the first letter in a paragraph, or insert some content before or after the element, etc.
In CSS1 and CSS2, the use of pseudo-elements is the same as pseudo-classes, and a colon :
is connected to the selector. However, in CSS3, the use of single colon for pseudo elements was changed to double colon ::
to distinguish pseudo classes and pseudo elements. Therefore, it is recommended to use double colons instead of single colons when using pseudo-elements.
The syntax structure is as follows:
/* CSS3 语法 */ 选择器::伪元素 { 属性 : 属性值; } /* CSS2 过时语法 (仅用来支持 IE8) */ 选择器:伪元素 { 属性 : 属性值; }
should now use two colons, unless you are also compatible with IE8.
Note: Only one pseudo-element can be used in a selector, and the pseudo-element must follow the selector. According to the latest W3C specification, you should use double colon
::
instead of single colon:
when defining pseudo-elements to distinguish pseudo-classes and pseudo-elements. However, since the old version of the W3C specification did not make a special distinction, most browsers currently support both single colon and double colon methods to define pseudo-elements.
CSS provides a series of pseudo-elements, as shown in the following table:
Pseudo-elements | Example | Example description |
---|---|---|
::after | p::after | Insert content after each element |
::before | p::before | Insert content before each element |
::first-letter | p::first-letter | Matches the first letter of the content in each element |
::first-line | p::first-line | Matches the first line of content in each element |
p::selection | Match the part of the element selected by the user | |
input::placeholder | Match the placeholder attribute of each form input box (such as ) |
The above is the detailed content of CSS pseudo-selector learning pseudo-element selector analysis. For more information, please follow other related articles on the PHP Chinese website!

For a while, iTunes was the big dog in podcasting, so if you linked "Subscribe to Podcast" to like:

We lost Opera when they went Chrome in 2013. Same deal with Edge when it also went Chrome earlier this year. Mike Taylor called these changes a "Decreasingly

From trashy clickbait sites to the most august of publications, share buttons have long been ubiquitous across the web. And yet it is arguable that these

In this week's roundup, Apple gets into web components, how Instagram is insta-loading scripts, and some food for thought for self-hosting critical resources.

When I was looking through the documentation of git commands, I noticed that many of them had an option for . I initially thought that this was just a

Sounds kind of like a hard problem doesn't it? We often don't have product shots in thousands of colors, such that we can flip out the with . Nor do we

I like when websites have a dark mode option. Dark mode makes web pages easier for me to read and helps my eyes feel more relaxed. Many websites, including

This is me looking at the HTML element for the first time. I've been aware of it for a while, but haven't taken it for a spin yet. It has some pretty cool and


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!