点击链接时不要改变链接的颜色

时间:2021-08-18 20:30:53

I have a link in an HTML page:

我在HTML页面上有一个链接:

<a href="#foo">foo</a>

The color of the link text is originally blue. When the link is clicked, the color of the link text changes to Red first, and then changes back to Blue. I want to the color of the link text not to change when user clicks on it. How can I make it happen?

链接文本的颜色最初是蓝色的。当单击链接时,链接文本的颜色首先变为红色,然后又变为蓝色。我想要链接文本的颜色不要在用户点击时改变。我怎样才能实现它呢?

I tried

我试着

a:active {
    color: none;
}

in CSS, but got no luck.

在CSS中,但没有运气。

And I don't want to use this in CSS:

我不想在CSS中使用这个

a:active {
    color: blue;
}

, because the original color of the link text can be some other than blue.

,因为链接文本的原始颜色可以不是蓝色的。

Thanks.

谢谢。

Edit: the page is displayed on iPhone browser, and I want to make a:active to keep the original link text color.

编辑:页面显示在iPhone浏览器上,我想让a:活动保持原来的链接文本颜色。

5 个解决方案

#1


49  

you are looking for this:

你在寻找:

a:visited{
  color:blue;
}

Links have several states you can alter... the way I remember them is LVHFA (Lord Vader's Handle Formerly Anakin)

链接有几个状态可以修改……我记得他们的方式是LVHFA(维德勋爵的手柄原来是阿纳金)

Each letter stands for a pseudo class: (Link,Visited,Hover,Focus,Active)

每个字母代表一个伪类:(链接、访问、悬停、焦点、活动)

a:link{
  color:blue;
}
a:visited{
  color:purple;
}
a:hover{
  color:orange;
}
a:focus{
  color:green;
}
a:active{
  color:red;
}

If you want the links to always be blue, just change all of them to blue. I would note though on a usability level, it would be nice if the mouse click caused the color to change a little bit (even if just a lighter/darker blue) to help indicate that the link was actually clicked (this is especially important in a touchscreen interface where you're not always sure the click was actually registered)

如果你想要链接总是蓝色的,只要把它们都改成蓝色就可以了。我会注意虽然在可用性的层面上,它就好了如果鼠标点击引起颜色变化一点(即使只是一个轻/深蓝色的)来表明链接实际上是点击(这是特别重要的在你并不总是确定的触摸屏界面点击实际上是注册)

If you have different types of links that you want to all have the same color when clicked, add a class to the links.

如果您有不同类型的链接,您希望它们在单击时都具有相同的颜色,那么向这些链接添加一个类。

a.foo, a.foo:link, a.foo:visited, a.foo:hover, a.foo:focus, a.foo:active{
  color:green;
}
a.bar, a.bar:link, a.bar:visited, a.bar:hover, a.bar:focus, a.bar:active{
  color:orange;
}

It should be noted that not all browsers respect each of these options ;-)

需要注意的是,并非所有浏览器都尊重这些选项;-)

#2


23  

I think this suits perfect for any color you have:

我觉得这适合任何颜色的衣服:

a {
    color: inherit;
}

#3


7  

just give

只给

a{
color:blue
}

even if its is visited it will always be blue

即使它被访问,它将永远是蓝色的

#4


0  

You need to use an explicit color value (e.g. #000 or blue) for the color-property. none is invalid here. The initial value is browser-specific and cannot be restored using CSS. Keep in mind that there are some other pseudo-classes than :active, too.

颜色属性需要使用显式的颜色值(例如#000或蓝色)。这里没有一个是无效的。初始值是特定于浏览器的,不能使用CSS进行恢复。请记住,还有一些其他的伪类:active。

#5


-1  

Don't over complicate it. Just give the link a color using the tags. It will leave a constant color that won't change even if you click it. So in your case just set it to blue. If it is set to a particular color of blue just you want to copy, you can press "print scrn" on your keyboard, paste in paint, and using the color picker(shaped as a dropper) pick the color of the link and view the code in the color settings.

不要过度复杂化。用标签给链接一个颜色。它会留下一个不变的颜色,即使你点击它也不会改变。在你的例子中,把它设为蓝色。如果它被设置为你想要复制的特定的蓝色,你可以在你的键盘上按下“print scrn”,在油漆中粘贴,使用颜色选择器(形状像滴管)选择链接的颜色并在颜色设置中查看代码。

#1


49  

you are looking for this:

你在寻找:

a:visited{
  color:blue;
}

Links have several states you can alter... the way I remember them is LVHFA (Lord Vader's Handle Formerly Anakin)

链接有几个状态可以修改……我记得他们的方式是LVHFA(维德勋爵的手柄原来是阿纳金)

Each letter stands for a pseudo class: (Link,Visited,Hover,Focus,Active)

每个字母代表一个伪类:(链接、访问、悬停、焦点、活动)

a:link{
  color:blue;
}
a:visited{
  color:purple;
}
a:hover{
  color:orange;
}
a:focus{
  color:green;
}
a:active{
  color:red;
}

If you want the links to always be blue, just change all of them to blue. I would note though on a usability level, it would be nice if the mouse click caused the color to change a little bit (even if just a lighter/darker blue) to help indicate that the link was actually clicked (this is especially important in a touchscreen interface where you're not always sure the click was actually registered)

如果你想要链接总是蓝色的,只要把它们都改成蓝色就可以了。我会注意虽然在可用性的层面上,它就好了如果鼠标点击引起颜色变化一点(即使只是一个轻/深蓝色的)来表明链接实际上是点击(这是特别重要的在你并不总是确定的触摸屏界面点击实际上是注册)

If you have different types of links that you want to all have the same color when clicked, add a class to the links.

如果您有不同类型的链接,您希望它们在单击时都具有相同的颜色,那么向这些链接添加一个类。

a.foo, a.foo:link, a.foo:visited, a.foo:hover, a.foo:focus, a.foo:active{
  color:green;
}
a.bar, a.bar:link, a.bar:visited, a.bar:hover, a.bar:focus, a.bar:active{
  color:orange;
}

It should be noted that not all browsers respect each of these options ;-)

需要注意的是,并非所有浏览器都尊重这些选项;-)

#2


23  

I think this suits perfect for any color you have:

我觉得这适合任何颜色的衣服:

a {
    color: inherit;
}

#3


7  

just give

只给

a{
color:blue
}

even if its is visited it will always be blue

即使它被访问,它将永远是蓝色的

#4


0  

You need to use an explicit color value (e.g. #000 or blue) for the color-property. none is invalid here. The initial value is browser-specific and cannot be restored using CSS. Keep in mind that there are some other pseudo-classes than :active, too.

颜色属性需要使用显式的颜色值(例如#000或蓝色)。这里没有一个是无效的。初始值是特定于浏览器的,不能使用CSS进行恢复。请记住,还有一些其他的伪类:active。

#5


-1  

Don't over complicate it. Just give the link a color using the tags. It will leave a constant color that won't change even if you click it. So in your case just set it to blue. If it is set to a particular color of blue just you want to copy, you can press "print scrn" on your keyboard, paste in paint, and using the color picker(shaped as a dropper) pick the color of the link and view the code in the color settings.

不要过度复杂化。用标签给链接一个颜色。它会留下一个不变的颜色,即使你点击它也不会改变。在你的例子中,把它设为蓝色。如果它被设置为你想要复制的特定的蓝色,你可以在你的键盘上按下“print scrn”,在油漆中粘贴,使用颜色选择器(形状像滴管)选择链接的颜色并在颜色设置中查看代码。