当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
mysql的innodb存储引擎和myisam存储引擎的区别
安装mysql-workbench
HCIP练习02(OSPF)
【无标题】
word之个人设置
gpnmb+ gpnmb-AT2 cell空转映射 上皮细胞的空转映射
ArcEngine(六)用tool工具实现拉框放大缩小和平移
并发之固定运行和交替运行方案
mysql5.7服务器The innodb_system data file 'ibdata1' must be writable导致无法启动服务器
How does Mysql query two data tables for the same fields in two tables at the same time
MySQL1
ArcEngine (1) Loading vector data
HCIA实验(07)
AI中台序列标注任务:三个数据集构造过程记录
netstat 及 ifconfig 是如何工作的。
day12---接口和协议
ArcEngine(三)通过MapControl控件实现放大缩小全图漫游
Mysql的in和exists用法区别
dflow入门3——dpdispatcher插件
分析型数据库性能测试总结









