Why is a pseudo-class so called?

前端 未结 5 580
甜味超标
甜味超标 2020-12-11 04:45
a:hover

Why is it called a \"pseudo-class\"?

Are there any similarities with the concept of \"class\"?

5条回答
  •  春和景丽
    2020-12-11 05:17

    With CSS2/3 allowing for more sophisticated element rules (things like input[type=checkbox] and the like, the term pseudo-class seems more and more dated.

    However, pseudo-classes are the only CSS identifiers that (more or less) reliably change with user interactions. With attribute selectors and what not, most browsers tend to go with the state of all elements on page load and any changes made are ignored. But with pseudo-classes, they actually change the style when the pseudo-class becomes true (or untrue).

    So with that specific definition in mind, they are classes because the rule applies to any elements that share the same "state" and thus can be considered of a "class", but it's pseudo because it isn't a true attribute-defined class and because the "class" may or may not be true at any given time the page is viewed.

    It's also interesting to note, I think, that with certain UI-based pseudo-classes (I'm thinking specifically of :hover) only one element at any given time can really have that "class" so it's almost more of a pseudo-id, based on my above definition.

提交回复
热议问题