Spicing Up a Table Using Background Color

In this section, I'll show you how to add a little spice to your tables using background colors. So far, you've used element selectors, which relate directly to a specific HTML element, such as body, h1, p, and a. In this section, you'll add what's known as a class selector.

Class selectors are custom selectors that you give a name to; you precede that name with a dot, as in .classname. Classes are then applied to an element in the HTML using the class attribute, with a value of the class name:

<tr class="classname"> . . . </tr>

Typically, you'll want to describe the function of the class rather than the presentation. So, if you're going to apply a background color to every other table row, you'll ...

Get Spring Into HTML and CSS 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.