XML technologies / CSS / CSS Cookbook / Typography for the web / Adding an image to the first line of a paragraph
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
You want to add an image to the first line of a paragraph, as shown in the following figure.
Figure: Background image in the first line of the paragraph.
Solution
Within the pseudo-element :first-line use the property background-image:
p:first-line {
font-size: 2em;
background-image: url(background.gif);
}Discussion
The pseudo-element :first-line affects only the text on an element’s first line, rather than the element itself. In addition to background-image the pseudo-element :first-line also supports the following properties that affect the design:
fontcolorbackgroundword-spacingletter-spacingtext-decorationvertical-aligntext-transformtext-shadowline-heightclear
Note that Internet Explorer 5 does not recognise the pseudo-element :first-line.
See also
The CSS 2.1 specification for the pseudo-element :first-line.
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