开发者

Am I allowed to use div:hover in my css?

开发者 https://www.devze.com 2023-01-14 19:53 出处:网络
Say my div class is called fred. Can I : .fred:hover { text-decoration:underline; } (I don\'t want to use an a tag)

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 l开发者_开发技巧egit code ?)


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


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


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 ^_^


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消