Html 如何从 CSS 中移除悬停效果?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19048867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:49:54  来源:igfitidea点击:

How to remove hover effect from CSS?

htmlcssclass

提问by PHPLover

I'm currently having a text as hyperlink and on this some CSS code is getting applied. Due to which on hover the text got underline and font gets bold on hover event. But now what I want to do is remove the hyperlink and apply the same effect bydefault i.e. not on hover. In short I want to apply the style currently applying on hover without hovering the text. My HTML and css code is as follows:

我目前有一个文本作为超链接,并且正在应用一些 CSS 代码。由于在悬停时文本带有下划线并且字体在悬停事件中变粗。但现在我想要做的是删除超链接并默认应用相同的效果,即不在悬停时。简而言之,我想应用当前应用于悬停的样式而不悬停文本。我的 HTML 和 css 代码如下:

.faq .section p.quetn a:hover {
    text-decoration:underline;
    font-weight:bold
}
<p class="quetn"><a href="">5.14 Where do i see my test results?</a></p>

One more important thig is I can't change the above written CSS, I want to override the above CSS code by writing a new class. Can you help me in achieving this? Thanks in advance.

一个更重要的事情是我无法更改上面编写的 CSS,我想通过编写一个新类来覆盖上面的 CSS 代码。你能帮我实现这个目标吗?提前致谢。

回答by martincarlin87

Just use the same rule for when the link is not being hovered:

当链接没有被悬停时,只需使用相同的规则:

.faq .section p.quetn a, .faq .section p.quetn a:hover {
    text-decoration:underline;
    font-weight:bold
}

EDIT

编辑

Juse seen that you can't change the CSS for some reason.

Juse 看到由于某种原因您无法更改 CSS。

Just create a new class with the same styles.

只需创建一个具有相同样式的新类。

a.class, a.class:hover {
    text-decoration:underline;
    font-weight:bold
}

<a class="class" title="" href="#">Some Link</a>

EDIT v2

编辑 v2

Do you want to style the text but remove the link markup?

您想设置文本样式但删除链接标记吗?

It would just be

它只是

<p class="class">Text</p>

p.class {
    text-decoration:underline;
    font-weight:bold
}

回答by Ganesh Pandhere

Then instead using

然后改为使用

.faq .section p.quetn a:hover

use

.faq .section p.quetn a

If you are targeting only P tag instead of anchor tag, then use it as below :

如果您只针对 P 标签而不是锚标签,请按如下方式使用它:

.faq .section p.quetn

回答by Falguni Panchal

Like this

像这样

demo

演示

css

css

.quetn a:hover {
    text-decoration:underline;
    font-weight:bold;
}

回答by Google User

html

html

<p class="quetn newClass"><a href="">5.14 Where do i see my test results?</a></p>    

css

css

.quetn a:hover {
        text-decoration:underline;
        font-weight:bold;
        cursor:default;
}

.newclass a:hover{
        text-decoration:none; !important
        font-weight:bold; !important
        cursor:default; !important
}

Use !important for priority.

使用 !important 优先。

回答by satish hiremath

Code below for Hover Enable

以下代码用于启用悬停

a:hover {
  background-color: yellow;
}

Code below for Hover Disable

以下代码用于禁用悬停

a:nohover {
  background-color: yellow;
}