如何在 CSS 中使用“悬停" [英] How to use 'hover' in CSS

查看:37
本文介绍了如何在 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;
    }

执行此操作的正确版本是什么?

What's the right version to do this?

推荐答案

如果您希望鼠标悬停在链接上时出现下划线,则:

If you want the underline to be present while the mouse hovers over the link, then:

a:hover {text-decoration: underline; }

就足够了,但是如果您愿意,您也可以使用悬停"的类名,以下同样适用:

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 的伪元素做了同样的事情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 中使用“悬停"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆