XML technologies / CSS / Advanced websites with CSS / Behind the scenes / Selectors and CSS rule structure / Element type selector
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
The most common selectors are individual elements without further qualification or extensions. A rule using an element type selector applies to every HTML element of that type unless another rule overrides it.
Table: CSS selector types.
Selector type | Effect | Examples in CSS syntax |
|---|---|---|
Universal selector | The rule applies to every element in the HTML document. | |
Element type | The rule applies to all HTML elements named in the selector. |
|
Class selector | The rule applies only to HTML elements whose attribute | |
ID selector | The rule applies only to the HTML element whose attribute | |
Pseudo-element selector (CSS2) | The rule applies only to pseudo-elements. | |
Pseudo-class selector (CSS2) | The rule applies only to pseudo-classes when their state changes through user interaction. | |
Descendant selector | The rule applies only to the rightmost HTML element in the selector if, through inheritance, it is a descendant of the element on the left. | |
Parent-child selector (CSS2) | The rule applies only to the rightmost HTML element if it is an immediate child of the element on the left. | |
Adjacent sibling selector (CSS2) | The rule applies only to the rightmost HTML element if it immediately neighbors the element on the left in the document. | |
Attribute selector (CSS2) | The rule applies only to HTML elements containing the attributes or attribute values specified in the selector. | |
The following example defines every hyperlink’s text and background colors as white on green:
a {
color: white;
background-color: green;
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg
back to top