HTML 默认链接颜色

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

HTML default link color

htmlcss

提问by Simon Perepelitsa

I want to set color of some elements to default link color with CSS.

我想使用 CSS 将某些元素的颜色设置为默认链接颜色。

<a href="/">That color</a> is the same as <span style="color: link;">that</span>.

Any way to do that? This website don't change default browser's link color.

有没有办法做到这一点?本网站不会更改默认浏览器的链接颜色。

回答by PatrikAkerstrand

Even if you don't change the default color, it would still be a good idea to specify the color to ensure that it looks the same in all browsers. I'd put something like this in the stylesheet:

即使您不更改默认颜色,指定颜色以确保它在所有浏览器中看起来都相同仍然是一个好主意。我会把这样的东西放在样式表中:

a, span.link {
  color: blue;
}

a:visited, span.visited {
   color: purple;
}

a:active, span.active {
   color: red;
}

Then you can style spans as links by <span class="link">Your fake link</span>

然后你可以将spans 设置为链接<span class="link">Your fake link</span>

回答by oezi

after some time messing around with testing pure css and css/javascript i'm sure you can't set the color of any other element to the default link-color of the browser - but like Machine said, you can try using classes to do this (but you won't be able to use the browser defaults, you have to set your own colors)

在测试纯 css 和 css/javascript 一段时间后,我确定您无法将任何其他元素的颜色设置为浏览器的默认链接颜色 - 但就像 Machine 所说,您可以尝试使用类来做这(但您将无法使用浏览器默认值,您必须设置自己的颜色)

回答by wiztrail

If you want to set to a new color for a link or to prevent the change of the color of a specific link aftervisiting it, add inside the <a>tag:

如果你想设置为一个新的颜色链接或防止特定链接的颜色变化访问过它,加上内部的<a>标签:

<A STYLE="text-decoration:none; color=[select your favorite...]" HREF="link.html">test link</A>