Give Your Table Rows a Little Extra Style

Sometimes the simplest items end up making the best blog posts. Lately I’ve really started to enjoy giving a mouse-over effect to each row in a table. (This could be in part because I frequently include links in my tables.) This practice certainly can’t replace the techniques that a web designer uses to make tables legible when the mouse pointer is off on some other part of the screen, but I think of it as a nice little extra.

First here’s an overview/refresher on a few of the most common methods for making a table easy to read:

Row Borders

Row Borders

This direct approach involves placing a line between each row, providing a guide for your eye to follow.

td { border-top-width: 1px; border-top-style: solid; border-top-color: #036; }

Zebra Tables

Zebra Tables

As noted by David F. Miller in his List Apart article on zebra tables, this is the approach that iTunes takes. Each row is an alternating color. To use the code below, make sure in your HTML that every other tr tag has the class alt.

tr.alt td { background-color: #ccf; }

Row Spacing

Row Spacing

Usually not very popular because it can quickly eat up vertical real estate, the idea here is to space each row far enough apart, that your eye can easily follow the data on a single row.

td { padding: 15px 5px; }

Mouse-over

Mouse-over

A mouse-over or hover effect on table rows can be used in combination with any of the above approaches (and usually is). When your mouse moves over a row, the background color changes.

tr:hover td { background-color: #ccc; }

Yes? You have a question there in the back? Well, no, this solution doesn’t work on every browser, most notably IE6. It does work on IE7, though, which is being adopted pretty quickly. Firefox, Safari, and Netscape all handle it. It also degrades gracefully on browsers that don’t recognize the hover pseudo class applied to a tr tag.

I don’t worry too much about it because I view the mouse-over color change for a row as a cool add-on. Your table should still be easy to read without it.

Not satisfied? Well, I commend you on your dedication to providing a consistent experience to all users regardless of browser preference. If you’re willing to dive into a little Javascript, here’s another approach.

3 Responses to “Give Your Table Rows a Little Extra Style”

  1. Excellent Article!
    Ironically I recently did something similar for a client with a large product data table. I wanted to go the extra step and make the entire row of the table a link.
    With some research I found this site: http://radio.javaranch.com/pascarello/2005/05/19/1116509823591.html
    If you are willing to step into a little javascript this was a great solution. I tweaked it a bit to still apply my initial style and the highlight style, but that was it.
    Keep up the great articles!

  2. Jordon, that approach to turning rows into links is clever and elegant. I wouldn’t have been sure where to begin if a client had asked me for this, so thanks for the arrow to add to my quiver!

  3. For those of you who want to do something like this for columns instead of rows, I saw this article with some advanced but easy to understand techniques in my feeds this morning:

    http://www.askthecssguy.com/2007/08/creating_a_table_with_dynamica.html

Leave a Reply

Best Practices

presented by Site Potion