XML technologies / CSS / CSS Cookbook / Typography for the web / Styling the first line of a paragraph
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
You want a paragraph’s first line to appear in bold, as shown in the following figure.
Figure: The first line of a paragraph appears in bold.
Solution
Use the pseudo-element :first-line to apply the style only to the first line:
p:first-line {
font-weight: bold;
}Discussion
Like a class selector, a pseudo-element selects particular parts of a web document. Unlike a class selector, however, resizing the browser window or changing the font size can alter the parts it matches. In this example, the length of the first line can change when the browser window is resized (see the following figure).
Note that Internet Explorer 5 does not recognise the pseudo-element :first-line.
Figure: Resizing the browser window also changes the affected text.
See also
The CSS 2.1 specification for the :first-line pseudo-element.
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