XML technologies / CSS / CSS Cookbook / Tables / Highlighting active table rows

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

A table row should be highlighted when the mouse pointer is over it (see the next figure).

Solution

Use the pseudo-class :hover together with the element selector tr:

tr:hover {
 background: yellow;
}

The table row under the mouse pointer is highlighted

Figure: The table row currently under the mouse pointer is highlighted.

Discussion

You may already know the pseudo-class :hover from creating rollover effects for links. However, the CSS specification does not restrict :hover to that use. It can be applied to any element, such as p or div.

This technique does not work everywhere, because Internet Explorer 6 for Windows and earlier versions do not support :hover.

See also

The CSS 2.1 specification on dynamic pseudo-classes.

  

 

 

 

back to top