当前位置:网站首页>What are pseudo-classes and pseudo-elements?The difference between pseudo-classes and pseudo-elements
What are pseudo-classes and pseudo-elements?The difference between pseudo-classes and pseudo-elements
2022-08-03 08:33:00 【Fire orchid】
First, understand what is a pseudo-class?What are pseudo-elements?
1. Pseudo-class types


The object of the pseudo-class is the entire element
a:link{color:#111}a:hover{color:#222}div:first-child{color:#333}div:nth-child(3){color:#444}Although these conditions are not DOM-based, the results each act on a complete element, such as an entire link, paragraph, div, etc.
2. Types of pseudo elements

Pseudo-element acts on part of an element: the first line or first letter of a paragraph
p::first-line{color:#555}p::first-letter{color:#666}a::before{content : "hello world";}3. Summary:
Pseudo elements are actually equivalent to forging an element. For example, the effect achieved by before and first-letter is to forge an element and then add its corresponding effect;
Pseudo-classes don't fake elements, for example first-child just adds styles to child elements.
The reason why pseudo-elements and pseudo-classes are so easy to confuse is because they have similar effects and are written in the same way, but In fact, in order to distinguish between the two, CSS3 has clearly stipulated that pseudo-classes are represented by a colon, and pseudo-classes are represented by a colon.Elements are represented by two colons.
But because of compatibility issues, most of them are still single colons. But aside from compatibility issues, we should develop a good habit when writing and distinguish between the two.
Second, the characteristics and differences between pseudo-classes and pseudo-elements
1. Pseudo-classes are essentially to make up for the inadequacy of regular CSS selectors in order to get more information
2. Pseudo-elements essentially create a virtual container with content
3. The syntax of pseudo-classes and pseudo-elements is different in CSS3
pseudo-class :link :hover single colon
Pseudo-elements ::before ::after Double colons
4. Multiple pseudo-classes can be used at the same time, but only one pseudo-element can be used at the same time
5. The fundamental difference between pseudo-classes and pseudo-elements is: whether they create a new element, this newly created element is called "pseudo-no-element"
6. Pseudo element/pseudo object: It does not exist in the DOM document, it is a virtual element, and it is to create a new element.
This new element (pseudo-element) is a child element of an element that exists logically but does not actually exist in the document tree
7. Pseudo-class: There are tags in the dom document, and the style is changed when the pseudo-class is used
8. Because pseudo-classes are similar to adding classes, there can be multiple ones, while pseudo-elements can only appear once in a selector and can only appear at the end
边栏推荐
猜你喜欢
随机推荐
sqlite date field plus one day
面渣逆袭:MySQL六十六问,两万字+五十图详解
gpnmb+ gpnmb-AT2 cell空转映射 上皮细胞的空转映射
Unity编辑器扩展批量修改图片名称
Guava的Service
Evaluate: A detailed introduction to the introduction of huggingface evaluation indicator module
【论文笔记】基于动作空间划分的MAXQ自动分层方法
基于二次型性能指标的燃料电池过氧比RBF-PID控制
pytorch one-hot 小技巧
线程介绍与使用
dflow入门1——HelloWorld!
数仓4.0(二)------ 业务数据采集平台
ArcEngine(三)通过MapControl控件实现放大缩小全图漫游
Add Modulo 10 (规律循环节,代码实现细节)
timestamp
“==”和equals的区别
Qt 下拉复选框(MultiSelectComboBox)(一) 实现下拉框多选,搜索下拉框内容
ArcEngine(五)用ICommand接口实现放大缩小
ArcEngine (six) use the tool tool to realize the zoom in, zoom out and translation of the pull box
110道 MySQL面试题及答案 (持续更新)









