XML technologies / CSS / Advanced websites with CSS / Behind the scenes / Selectors and CSS rule structure / Selector for pseudo-classes

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

The pseudo-class selector is similar to the pseudo-element selector, with one exception: under certain circumstances, it can refer to an entire element rather than just a property.

The current version of CSS 2 contains the following pseudo-classes:

Style rules for these pseudo-classes can be defined in a stylesheet, as the following example shows. You may remember that we have already encountered a rule for the pseudo-class :hover.

a:hover {
  color:green;
}

With this style rule, all text and images enclosed in a tag <a> change color when the user points to them with the mouse. The pseudo-class selector only takes effect when an element enters a particular state.

The pseudo-class :lang determines the setting of the language attribute lang for an HTML element. (Note: Browser support for the pseudo-class :lang() is still very incomplete. It is mentioned here only for completeness.) The following HTML tag marks a paragraph as German-language content:

<p lang="de">Deutsche Grammophon</p>

The following style rule defines the typeface for all German-language elements on the page:

:lang(de) {
  font-family: spezialitaet;
}

lang vs language
Be careful! Do not confuse the attribute lang with the attribute language, which specifies a scripting language used in a tag or on a page.

  

 

 

 

back to top