简体   繁体   中英

Why ::first-letter is a pseudo element and not a pseudo class?

I was going through the pseudo classes and elements in CSS.

Till now i read that pseudo classes are used to select elements that are in specific state.

And pseudo elements are used to add virtual elements like::before and::after.

I am confused that how come ::first-letter and ::first-line are pseudo elements and not pseudo classes? Because they are also selecting elements in specific state.

Because they are also selecting elements in specific state.

They are not. They are selecting contents.

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 (eg, the::before and::after pseudo-elements give access to generated content). ref

and

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. ref

They cannot be pseudo classes because their selection lies inside the document tree.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM