XML technologies / CSS / CSS Cookbook / Typography for the web / Drop capitals at the start of a paragraph
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
A paragraph should begin with a drop capital. The term drop capitals refers to especially large letters at the start of a paragraph, several points larger than the remaining text or often several lines high.
Solution
Place the paragraph in a p element:
<p>Online, activity of exchanging ideas is sped up. The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology …</p> Now use the pseudo-element :first-letter to give the paragraph’s first letter a special style (see the following figure):
p:first-letter {
font-size: 1.2em;
background-color: black;
color: white;
}Figure: A simple drop capital.
Discussion
The CSS specification’s pseudo-element :first-letter provides an easy way to turn a paragraph’s first letter into a drop capital. :first-letter is now supported by most modern browsers, such as Internet Explorer 6 for Windows, Firefox, Safari and Opera. For other browsers, the following approach may help:
Enclose the first letter of the paragraph’s first sentence in a span element containing a class attribute:
<p><span class="initcap">O</span>nline, activity of exchanging ideas is sped up. The distribution of messages from the selling of propaganda to the giving away of disinformation takes place at a blindingly fast pace thanks to the state of technology …</p>You can now define a custom style for the first letter:
p .initcap {
font-size: 1.2em;
background-color: black;
color: white;
}See also
The CSS 2.1 specification for the :first-letter 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