tags:

views:

47

answers:

4

Say my div class is called fred. Can I :

.fred:hover
{
text-decoration:underline;
}

(I don't want to use an a tag) (I know it works in some browsers but the question is really is it legit code ?)

A: 

If your div has a class of fred then yes, if your div has an id of fred you need #fred:hover

EDIT: Which reading your question again, you've said it is a class ^_^

Byron Cobb
+1  A: 

Why not just try it out

Demo: http://jsfiddle.net/T5NtN/

Your solution is standards compliant so yes you are allowed to use it. However some older browsers such as IE6 only allow :hover on <a> tags

irishbuzz
A: 

Certainly you can. I'm not clear what part of your example you think might be dubious.

That will cause any object with class 'fred' to show its text underlined while you hover over it.

Colin Fine
My question was really whether it was acceptable practice or not ?
Fred
The dubious part is that it won't always work, so actually, he can't. ;)
Caspar Kleijne
@Caspar, but it's standards-compliant so he *can*, so long as he accepts it's not universally supported. And, quite frankly, if the UK's NHS is finally moving up to IE7 I'd imagine that all but the most contrary corporations will follow within a year or so.
David Thomas
+1  A: 

Yes you can, but it won't work in some (older-) browsers. Javascript can do the job in a more multi-browser way ;) So your wishes do not meet global technology.....yet :O

Caspar Kleijne
It meets the standards, it's just that some browsers don't implement the standards, yet.
David Thomas
edited that. Thanks ;)
Caspar Kleijne