Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Colorizing Tables

When tables are very wide, the eye may wander up or down onto another row. Providing a different background or font color for every two or three rows helps the reader's eye focus on the correct data.

I'll show you how to do that.

I'll also show you how to highlight single data cells to make them stand out.

Here is an overview of how to do it:

  1. Define two CSS classes:

    • A class to apply to specific table rows.
    • A class to apply to specific table data cells.
  2. To colorize tables rows and individual table data cells:

    • To colorize an entire table row, use the CSS class for table rows in the TR tag.
    • To colorize an individual table data cell, use the CSS class for table data cells in the TD tag.
  3. To colorize an entire table column: Use the CSS class for table data cells in every TD tag of the column.

    (The HTML tags COL and COLGROUP do not work as expected in several popular browsers. I recommend colorizing each TD tag of the column, instead.)

Here is an example. The code follows.

Water Air Fire Earth
Spring thunderclouds Yes Yes No No
Roasting chestnuts No No Yes Yes
Winter snowbanks Yes Yes No Yes
Ice cream on a hot summer day Yes Yes Yes Yes

In practice, the colors may be more subtle. The dramatic colors in the example are for demonstrating with clarity.

Here are the CSS definitions the example uses to colorize a table row and a table data cell.

<style type="text/css">
.enhancedrow { background-color:yellow; font-weight:bold; }
.enhancedcell { background-color:blue; color:white; }
</style>

Change the definitions as you see fit. Things to consider: A different font. Different colors. Different font sizes. Borders. Background image instead of solid color.

Here is the table. It is marked with "***" where the CSS definitions are used.

<table border="1" cellpadding="5" cellspacing="0">

<tr>
<th></th>
<th>Water</th>
<th>Air</th>
<th>Fire</th>
<th>Earth</th>
</tr>

<tr>
<td>Spring thunderclouds</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
</tr>

<tr>
<td>Roasting chestnuts</td>
<td>No</td>
<td>No</td>
<!-- *** Table data cell colorized on next line *** -->
<td class="enhancedcell">Yes</td>
<td>Yes</td>
</tr>

<!-- *** Table row colorized on next line *** -->
<tr class="enhancedrow">
<td>Winter snowbanks</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
</tr>

<tr>
<td>Ice cream on a hot summer day</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>

</table>

If a colorized table data cell is located in a colorized row, the data cell will be the data cell's specified style and the rest of the row will be the row's specified style.

Whenever you have a very wide table or want to emphasize specific table rows or data cells, make a CSS definition and use it in the table.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC