Html 单击链接时不要更改链接颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4383460/
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
Don't change link color when a link is clicked
提问by Kai
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 浏览器上,我想制作一个:活动以保持原始链接文本颜色。
回答by scunliffe
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(Lord Vader's Handle,以前是 Anakin)
Each letter stands for a pseudo class: (Link,Visited,Hover,Focus,Active)
每个字母代表一个伪类:(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 ;-)
应该注意的是,并非所有浏览器都尊重这些选项中的每一个 ;-)
回答by Mihai
I think this suits perfect for any color you have:
我认为这适合您拥有的任何颜色:
a {
color: inherit;
}
回答by Anish Joseph
just give
就给
a{
color:blue
}
even if its is visited it will always be blue
即使它被访问它也将永远是蓝色的
回答by jwueller
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
或blue
)color
。none
在这里无效。初始值是特定于浏览器的,不能使用 CSS 恢复。请记住,除了 之外,还有一些其他的伪类:active
。
回答by Unknown
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”,粘贴油漆,然后使用颜色选择器(形状为滴管)选择链接的颜色并查看颜色设置中的代码。