tags:

views:

394

answers:

5

Is the anchor tag the only element in HTML to support styles like hover, active, visited?

I was thinking of using these styles for easier cell rollover effects in a datagrid. But I can't seem to get these styles working on anything other than the most basic of tag.

+2  A: 

It should work on all elements, but IE6 only supports in on links. I used whatever:hover to work around that.

buti-oxa
+2  A: 

Modern browsers support the pseudo style properties for all elements, IE6 is the only current wide-spread browser that doesn't (and that's only for the :hover property).

It is unfortunate but until IE6 usage drops below minimal levels, you should avoid using the :hover property on non-anchor elements for better cross-browser support. Alternatively, you can provide IE6 support for it using javascript (with browser detection) or CSS expressions.

Eran Galperin
A: 

Yes unfortunately anchor is the only tag that supports these styles.

I would recommend the following: Before coding any of your own JS, try use the JQuery framework, it might save you loads of work.

Another crazy workaround would be to expand the size of the using style to 100% of the parent (cell), this way you would effectively be applying the style to the cell.

Michael L
A: 

According to the CSS2 specification:

CSS doesn't define which elements may be in the above states [:hover, :active, and :focus], or how the states are entered and left.

In other words, don't depend on them working at all. I would use Javascript, along with CSS, to get a wider audience.

strager
A: 

PPK has a great reference for browser compatibility here: http://www.quirksmode.org/css/contents.html#t16

It shows the browsers that correctly support the :hover pseudoclass (and lots of other css selectors).

willoller