在正式开始之前我们先看一下他们的定义
伪元素(Pseudo-elements)
Pseudo-elements create abstractions about the document tree beyond those specified by the document language. For instance, document languages do not offer mechanisms to access the first letter or first line of an element’s content. Pseudo-elements allow authors to refer to this otherwise inaccessible information. Pseudo-elements may also provide authors a way to refer to content that does not exist in the source document.
核心就是需要创建通常不存在于文档中的元素
伪类(pseudo-classes)
The pseudo-class concept is introduced to permit selection based on information that lies outside of the document tree or that cannot be expressed using the other simple selectors.
核心就是用来选择那些不能够被普通选择器选择的文档之外的元素。比如:hover
所以,伪类和伪元素都是用来表示文档树以外的“元素”
二者的区别关键在于:若没有伪元素(或伪类),是否需要添加元素才能达到目的。若是则是伪元素,反之则是伪类