Applying Column-Based Formatting

Column groups are handy for applying formatting to entire columns. For example, suppose you decide that all the text in the column farthest to the right should be italicized. You could do that by inserting italics tags in each cell, but that becomes a less-attractive option when there are hundreds of rows.

The <colgroup> tag can be used as either a one-sided or two-sided tag. As a one-sided tag, you can specify styles that will be applied to the current column and continue for a specified number of columns. For example, to apply a yellow background to the first column, create a column group immediately following the opening <table> tag:

<colgroup span="1" style="background-color: yellow" />

You can increase the span ...

Get HTML and XHTML Step by Step now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.