如何在CSS中使用“hover” [英] How to use 'hover' in CSS
问题描述
我使用以下代码来实现此目标:
I used the code below in order to fulfill this target:
当鼠标悬停在锚点上时,下划线出现,
When mouse hover on the anchor, the underline comes out,
但无法正常工作,
<a class="hover">click</a>
a .hover :hover{
text-decoration:underline;
}
正确的版本是什么?
推荐答案
如果您希望在鼠标悬停在链接上时显示下划线,则:
If you want the underline to be present while the mouse hovers over the link, then:
a:hover {text-decoration: underline; }
就足够了,但是你也可以使用'hover'并且以下同样适用:
is sufficient, however you can also use a class-name of 'hover' if you wish, and the following would be equally applicable:
a.hover:hover {text-decoration: underline; }
顺便提一下,值得指出的是'hover'的类名并不真正添加任何东西到元素,因为 a:hover
的psuedo元素做与 a.hover:hover
。除非它只是一个使用类名的演示。
Incidentally it may be worth pointing out that the class name of 'hover' doesn't really add anything to the element, as the psuedo-element of a:hover
does the same thing as that of a.hover:hover
. Unless it's just a demonstration of using a class-name.
这篇关于如何在CSS中使用“hover”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!