XML technologies / CSS / CSS Cookbook / Tables / Styling table captions
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
A table’s description (caption) should have its own styles.
Solution
Use the element selector caption:
table caption {
font: 1.5em Georgia, "Times New Roman", Times, serif;
padding: 1em;
}Discussion
Captions explain a table’s contents and should appear in the HTML code after the opening table element, but before all other elements such as thead or tr:
<table id="shoppingcartTable" summary="Liste der Produkte in Ihrem Warenkorb.">
<caption>Ihr Warenkorb - <strong>Summe: 45,16 ¤</strong>; Menge ändern <input type="submit" value="Preis(e) aktualisieren" /></caption>
...
</table>Although the appearance of the element caption may differ between browsers, all browsers display it. It can be styled with CSS and is the most accessible way to add captions to tables.
See also
The HTML 4.01 specification for the property caption.
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