Html CSS a:link 保持原始颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6850023/
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
CSS a:link keep original color
提问by Warface
Is it possible to tell a link not to change color in CSS and use the default one.
是否可以告诉链接不要在 CSS 中更改颜色并使用默认颜色。
Example
例子
I have a text in red and that text is a link too. Normaly that text will change blue because it's a link, but I want it to stay red.
我有一个红色文本,该文本也是一个链接。通常该文本会变成蓝色,因为它是一个链接,但我希望它保持红色。
So is there a global style for a:link to select no color at all ?
那么 a:link 是否有一个全局样式可以根本不选择颜色?
回答by Pa?lo Ebermann
Try this in your stylesheet:
在你的样式表中试试这个:
a:link {
color:inherit;
}
Note that you then probably should make sure you have some other way to identify links, or your users will be confused. (I.e. don't remove the underlining, too.)
请注意,您可能应该确保您有其他方法来识别链接,否则您的用户会感到困惑。(即也不要删除下划线。)
If you want to deal with browsers not supporting inherit
, I suppose repeating the definition which originally set your color will do.
如果你想处理不支持的浏览器inherit
,我想重复最初设置你的颜色的定义就可以了。
As an example, assume the class important
should be shown in red:
例如,假设该类important
应显示为红色:
.important {
color:red;
}
.important a:link {
color:red;
}
But of course it is not nice to have to double all color indications. I assume one could do something in JavaScript (looping through all the a
elements and giving them the right class explicitly). (I have no IE available to test this.)
但当然,必须将所有颜色指示加倍并不好。我假设可以用 JavaScript 做一些事情(循环遍历所有a
元素并明确地为它们提供正确的类)。(我没有可用于测试的 IE。)
回答by ayyp
If all of your a
tags are contained within a paragraph tag you can just set the color
of the a
tag to inherit
. You could also just set a style for all a
tags to have whatever colour the paragraph tag has. A quick warning about inherit
, there are older versions of IE which don't support it(IE7 and earlier).
如果所有的a
标签都包含一个段落标记中你可以设置color
的的a
标签inherit
。您也可以为所有a
标签设置一个样式,使其具有段落标签的任何颜色。关于 的快速警告inherit
,有旧版本的 IE 不支持它(IE7 及更早版本)。