简体   繁体   English

如何在悬停时不改变链接的颜色

[英]How to not change color of link on hover

I am using metro-ui-css in MVC5 app and have a menu. 我在MVC5应用程序中使用metro-ui-css并有一个菜单。 Now I do not want to change the color of my menu link at all. 现在我根本不想改变菜单链接的颜色。 The menu navbar looks as follows: 菜单导航栏如下所示:

 <nav class="navigation-bar-content">
            <a href="@Url.Action("Index", "Home")"><item class="element">A Thousand Counts</item></a>
            <item class="element-divider"></item>
            <item class="element">...</item>
        </nav>

While adding the following css: 在添加以下css时:

.element > a, a:active, a:hover, a:link, a:visited {
    color: white;
}

I managed to keep the color of the link white as I want it to be. 我设法将链接的颜色保持为白色,就像我想要的那样。 Unfortunately, on hover it still turns blue. 不幸的是,在悬停时它仍然变成蓝色。 How can I change this behaviour and keep it white? 如何更改此行为并保持白色? I tried: 我试过了:

a:hover {
    color: white;
}

but it is not working. 但它不起作用。 I would be grateful it someone with CSS skills could help me out! 我很感激有CSS技能的人可以帮助我!

In your CSS definitions, there could be other styles with more specificity that get higher priority hence overriding your defined style. 在CSS定义中,可能存在具有更高特异性的其他样式,这些样式具有更高的优先级,因此会覆盖您定义的样式。

Based on your posted HTML, this will most probably do the job for you: 根据您发布的HTML,这很可能会为您完成这项工作:

.navigation-bar-content a:hover {
    color: white;
}

Arbel's tip is great! 阿贝尔的小费很棒! If you get stuck on these types of issues and cannot find the culprit, sometimes workarounds like these help: 如果您遇到这些类型的问题并且无法找到罪魁祸首,有时候这样的解决方法会有所帮助:

<nav class="navigation-bar-content">
    <a href="@Url.Action("Index", "Home")"><item class="element"><span class="workaround">A Thousand Counts</p></span></a>
            <item class="element-divider"></item>
            <item class="element">...</item>
        </nav>

.workaround > a, a:active, a:hover, a:link, a:visited {
    color: red;
}

Thanks to the comment by Arbel the problem is solved. 感谢Arbel的评论,问题解决了。 By adding !important: 通过添加!important:

.element > a, a:active, a:hover, a:link, a:visited {
    color: white!important;
}

the menu stays white. 菜单保持白色。 Great! 大!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM