CSS 2.1 Selectors, Pseudo-Classes, and Pseudo-Elements: Appendix C - CSS Cookbook, Third Edition
by Christopher SchmittThis excerpt is from CSS Cookbook, Third Edition.
Learn how to solve the real problems you face with CSS. This cookbook offers hundreds of practical examples for using CSS to format your web pages, and includes code samples you can use right away. You'll find exactly what you need, from determining which aspects of CSS meet the specific needs of your site to methods for resolving differences in the way browsers display it.
This appendix contains three reference tables that can help you learn how to apply styles to the correct elements.
Table C.1, “CSS 2.1 selectors” contains the CSS 2.1 selectors. Selectors help tell the browser where to apply the CSS declarations.
Note
In the “Generic pattern” column of Table C.1, “CSS 2.1 selectors”, the values C,
R, and S take the place of type
selectors.
Table C.2, “CSS 2.1 pseudo-classes” contains a list of pseudo-classes. A pseudo-class is a device by which a browser applies an invisible class on its own. For example, through the pseudo-class we are able to define properties for various visited, active, and hover states of the ubiquitous link.
Table C.3, “CSS 2.1 pseudo-elements” contains a list of pseudo-elements. Similar in nature to a pseudo-class, a pseudo-element places invisible tags around content in a web page and then applies styles to that element. Since the structure is more like a typical element than a class, these elements are called pseudo-elements.
Table C.1. CSS 2.1 selectors
|
Selector |
Generic pattern |
Description |
Sample |
|---|---|---|---|
|
|
Matches with any element |
| |
|
|
Matches any element; in this
example, all |
| |
|
|
Matches any
|
| |
|
|
Selects any
|
| |
|
|
Selects any
|
| |
|
|
Several selectors utilize the same declaration(s) |
| |
|
|
Selects any
|
| |
|
|
Selects any
|
| |
|
|
Selects any
|
| |
|
Attribute selector |
|
Selects any
|
|
|
Attribute selector |
|
Selects any
|
|
|
Attribute selector |
|
Selects any
|
|
Table C.2. CSS 2.1 pseudo-classes
|
Pseudo-class |
Generic pattern |
Description |
Sample |
|---|---|---|---|
|
|
Matches element
|
| |
|
|
Matches any unvisited link of
element |
| |
|
|
Matches any visited link of
element |
| |
|
|
Matches the
|
| |
|
|
Matches the
|
| |
|
|
Matches the
|
| |
|
|
Matches the
|
|
Table C.3. CSS 2.1 pseudo-elements
|
Pseudo-element |
Generic pattern |
Description |
Sample |
|---|---|---|---|
|
|
Selects the first line of
text in the |
| |
|
|
Selects the first letter in
the |
| |
|
|
Places generated content
before an element; used with the |
| |
|
|
Places generated content
after an element; used with the |
If you enjoyed this excerpt, buy a copy of CSS Cookbook, Third Edition.
