简体   繁体   English

链接颜色变化

[英]Link color change

I have a link called "Navigation" I want the link colour to change as I click on it and stay changed. 我有一个名为“导航”的链接,我希望链接颜色在单击时保持不变。 For example: Default colour is blue. 例如:默认颜色是蓝色。 When I click on the link it goes to another tab and the color turns to green and it should remain green. 当我单击链接时,它会转到另一个选项卡,并且颜色变为绿色,并且应该保持绿色。

here is the code so far: 这是到目前为止的代码:

<style type="text/css"> 
 a.specialAnchor 
{
    font-size: 1em;
    text-align: right;
    padding: 10px;
    padding-right: 15px;
    color: #0066FF;
}
a.specialAnchor:link
{    
color: #0066FF;
}
a.specialAnchor:visited
{    
color: Green;
}
a.specialAnchor:hover 
{
  color:Orange;
  text-decoration:underline;
}
a.specialAnchor:active 
{
 color: Green;
 text-decoration:underline;
}

 <asp:LinkButton ID="Navigation" runat="server" BorderStyle="None" CssClass ="specialAnchor"
                 PostBackUrl="~/navigation.aspx">Navigation</asp:LinkButton>

This does not give me the results I want Please help. 这没有给我我想要的结果,请帮助。

Basically my webpage looks a something like this: there are four tabs: A, Navigation, C, D And in all those four tabs there are links at the bottom of the page. 基本上,我的网页看起来像这样:有四个选项卡:A,导航,C,D。在所有这四个选项卡中,页面底部都有链接。 When you are on A and you click on Navigation link, it will take you to Navigation page. 当您在A上并单击“导航”链接时,它将带您进入“导航”页面。 What I want is to change the colour of the link when it is clicked on or visited. 我想要的是单击或访问链接时更改链接的颜色。

Thank you 谢谢

Have you tried changing the color of the visited pseudo class to green? 您是否尝试过将访问的伪类的颜色更改为绿色? Try that and see if works the way you want? 尝试一下,看看是否可以按照您想要的方式工作?

Ok, given that you have a link like this 好的,假设您有这样的链接

<a class="spec" href="wherever">Link</a>

You need styles like this 您需要这样的样式

<style type="text/css">
.spec:link {color:#FF0000;}    /* unvisited link */
.spec:visited {color:#00FF00;} /* visited link */
.spec:hover {color:#FF00FF;}   /* mouse over link */
.spec:active {color:#0000FF;}  /* selected link */
</style>

Done on the tryit editor at w3schools :) 在w3schools的tryit编辑器上完成的:)

If changing your :visited pseudoclass doesn't give you what you want, try changing the style onclick with jQuery: 如果更改:visited伪类不能满足您的要求,请尝试使用jQuery更改onclick样式:

$('a.specialAnchor').click(function() {
    this.style.color = 'green';
}

Try something like this 试试这个

$(document).ready(function () {
            $('.changecolor').click(function () {
                $(this).css("color", "red");
            });    
        });

<a class="changecolor">Click To Change</a>

If you need to change the color back to what it was, you can use .toggle() 如果需要将颜色改回原来的颜色,可以使用.toggle()

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

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