views:

57

answers:

4
a:hover

Why is the so-called "pseudo class" so called?

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

+2  A: 

It's pseudo because you didn't make it; the browser 'created' it and allows you to set it to change the look of the link when it's in that state.

Noon Silk
but why is it a class? If you can only hover or one area of the screen at a time, then only one p can take the CSS rule at any time. Doesn't class imply several elements belonging to some common group, and a class style rule means all of them will inherit that rule?
Anthony
@Anthony: The pseudo-class can be assumed as a state. And every element that has the state *hover* can be classified by `:hover`. So whenever a `a` element gets the state *hover*, it can be selected with `:hover`.
Gumbo
+1  A: 

In CSS terms, a class is a selector that stars with a full stop, e.g.

.foo { ... }

It would be used in the form

<div class="foo">

This use of "class" is more in the sense "a set or category of things having a common characteristic and differentiated from others by kind or quality", rather than borrowing from OO terminology

A pseudo class is "not quite a real one" as the user agent defines when and/or how much content qualifies (like :hover, :first-line, etc.)

Rowland Shaw
+1  A: 

From the w3c CSS2 selector spec:

CSS introduces the concepts of pseudo-elements and pseudo-classes to permit formatting based on information that lies outside the document tree.

  • 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. CSS pseudo-elements allow style sheet designers to refer to this otherwise inaccessible information. Pseudo-elements may also provide style sheet designers a way to assign style to content that does not exist in the source document (e.g., the :before and :after pseudo-elements give access to generated content).

  • Pseudo-classes classify elements on characteristics other than their name, attributes or content; in principle characteristics that cannot be deduced from the document tree. Pseudo-classes may be dynamic, in the sense that an element may acquire or lose a pseudo-class while a user interacts with the document. The exceptions are ':first-child', which can be deduced from the document tree, and ':lang()', which can be deduced from the document tree in some cases.

So basically, a pseudo-class is something you can attach a style to, but you never print it out yourself in the HTML. Also, a pseudo-clas can be aquired and lost depending on user interaction with the UI.

PatrikAkerstrand
A: 

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.

Anthony