CSS ASP.NET MVC Html.ActionLink 超链接颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7073705/
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-30 01:18:37  来源:igfitidea点击:

ASP.NET MVC Html.ActionLink hyperlink color

cssasp.net-mvc

提问by Ronald

How can I change the colors of the hyperlink created by the helper function Html.ActionLink?

如何更改辅助函数 Html.ActionLink 创建的超链接的颜色?

[additional detail] The colors will have to be different for each state of the hyperlink, i.e. active, selected, was already selected, etc.

[附加细节] 超链接的每个状态的颜色必须不同,即活动、选中、已选中等。

回答by dahlbyk

Typically you would do something like this:

通常你会做这样的事情:

Html.ActionLink("My Link", "MyAction", null, new { @class = "my-class" })

And then use CSS to style my-class:

然后使用 CSS 设置样式my-class

a.my-class { color: #333333 }
a.my-class:active { color: #666666 }
a.my-class:link { color: #999999 }
a.my-class:visited { color: #CCCCCC }

回答by p.campbell

The ActionLink()method is overloaded. Some of those signatures allow for the passing of a parameter object htmlAttributes.

ActionLink()方法已重载。其中一些签名允许传递参数object htmlAttributes

You can do something like this:

你可以这样做:

Html.ActionLink("foo", "bar","baz",   
            new { id = 1}, //   Route args if needed; null if not.
            new {@style="color:#000aaa;" }
            );

Perhaps you have a CSS class already defined:

也许你已经定义了一个 CSS 类:

Html.ActionLink("foo", "bar","baz",   
            new { id = 1}, //   Route args if needed; null if not.
            new {@class="MyClass;" }
            );

回答by Carlos Liu

Some explainations base on @dahlbyk answer

一些基于@dahlbyk 回答的解释

  • a:link- a normal, unvisited link
  • a:visited- a link the user has visited
  • a:hover- a link when the user mouses over it
  • a:active- a link the moment it is clicked
  • a:link- 一个正常的、未访问的链接
  • a:visited- 用户访问过的链接
  • a:hover- 当用户将鼠标悬停在它上面时的链接
  • a:active- 点击链接时的链接

When setting the style for several link states, there are some order rules:

在为多个链接状态设置样式时,有一些顺序规则:

  • a:hover MUST come after a:link and a:visited
  • a:active MUST come after a:hover
  • a:hover 必须在 a:link 和 a:visited 之后
  • a:active 必须在 a:hover 之后

More detailes can be found here

更多细节可以在这里找到

回答by Niroshan Kumarasamy

try, this way also will helpful to someone

尝试,这种方式也会对某人有所帮助

Html.ActionLink("Your Link", "YourAction")

<style>   
  a{
        color: #FF5722;
        text-decoration: none;
    }

//if needed hover
  a:hover {
            color: #FF5722;
     }
//Likewise active,visited
</style>