Book HomeCascading Style Sheets: The Definitive GuideSearch this book Wednesday 23rd of July 2014 10:07:43 PM

10.7. Tables

Perhaps as a result of a generic need to be able to describe table layout -- something CSS1 lacks -- CSS2 includes a handful of features that apply directly to tables and table cells. First, there are 10 new table-related values for display:

table
inline-table
table-column-group
table-column
table-row-group
table-row
table-cell
table-caption
table-header-group
table-footer-group 

While the effects of most of these are obvious from their names, at aspect of vertical formatting, which is the collapsing of adjacentmargins. This comes into play when an element with declared marginsimmediately follows another such element in the document'slayout. This was discussed in the previous chapter, using thisexample:

LI {margin-top: 10px; margin-bottom: 20px;}

Padding and borders, where they exist, are never collapsed. Ifneither is declared, then both will default to 0(zero). This assumes that no style is set for the border. If a border least two may not be familiar to you. table-header-group and table-footer-group are used to mark the header and footer of a table. These are displayed, respectively, above or below all the rows of the table, but not outside of the table's caption.

Another interesting effect is that you can align text on a character by using the text-align property. For example, if you wanted to line up a column of figures on a decimal point, you might declare:

TD { text-align: "." }

As long as a set of cells are grouped into a column, their content will be aligned so that the periods all line up along a vertical axis.

Far from relying on existing properties, CSS2 provides a whole array of brand-new properties in the table section. Here are a few of them:

There are also properties describing how visibility and vertical-align are applied to tables. There is also a caption-side property, which functions exactly the same as the ALIGN attribute on the <CAPTION> tag, and the property speak-header-cell, which controls how header cells are handled by speech-generating browsers (more on that later).



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.

might decide to color it red. All that's needed is a class ofwarn on each paragraph that contains warning text(<P CLASS="warn">) andthe following rule:

P.warn {color: red;}
P.warn {color: red;}P.warn A:link {color: green;}

Then you change your mind, deciding that warning text should be grayand that links in such text should be silver. The preceding rulesstyles, of course, as shown in Figure 7-78. Despitethe document-wide rule that H2 elements will notpermit floated elements to either side, one H2 inparticular has been set so that it does permit floated elements oneither side:

H2 {clear: both;}<H2 STYLE="clear: none;">Not Cleared!</H2>
Figure 7-78

Figure 7-78. Not clear at all

clear works by increasing the top margin of an