XML technologies / CSS / CSS Cookbook / General topics / Different selectors for assigning styles / Pseudo-elements
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
In most cases, web developers assign styles using selectors that refer to elements and their position in the document. However, certain parts of a document can also be addressed without special markup. This is done using the so-called pseudo-elements :first-letter, :first-line, :before and :after.
Here is an example using the pseudo-element :first-letter. The following figure shows the browser rendering:
p:first-letter {
font-size: 200%;
font-weight: bold;
}Figure: The first letter has its own styles.
Alternatively, use :first-line (see the following figure) to style the entire first line. Even if the first line does not contain a complete sentence or includes the start of a second sentence, the rules defined with :first-line always apply to the entire first line.
p:first-line {
font-size: 200%;
font-weight: bold;
}Figure: The entire first line has its own styles.
See also
Further information is available in the CSS 2.1 specification, in the section on selectors. Selectutorial is a tutorial on using CSS selectors. Westciv: browser support - Selectors shows which browsers support which selectors. CSS 2.1: selectors, pseudo-classes and pseudo-elements contains a list of CSS selectors.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” 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.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln