CSS a:link 保持原始颜色 [英] CSS a:link keep original color

查看:24
本文介绍了CSS a:link 保持原始颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以告诉链接不要在 CSS 中更改颜色并使用默认颜色.

Is it possible to tell a link not to change color in CSS and use the default one.

示例

我有一个红色文本,该文本也是一个链接.通常文本会变成蓝色,因为它是一个链接,但我希望它保持红色.

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.

那么 a:link 是否有一个全局样式来完全不选择颜色?

So is there a global style for a:link to select no color at all ?

推荐答案

在您的样式表中试试这个:

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.)

如果你想处理不支持inherit的浏览器,我想重复最初设置你的颜色的定义就可以了.

If you want to deal with browsers not supporting inherit, I suppose repeating the definition which originally set your color will do.

举个例子,假设类 important 应该显示为红色:

As an example, assume the class important should be shown in red:

.important {
    color:red;
}

.important a:link {
    color:red;
}

当然,将所有颜色指示加倍并不好.我假设可以用 JavaScript 做一些事情(循环遍历所有 a 元素并明确地为它们提供正确的类).(我没有可用于测试的 IE.)

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.)

这篇关于CSS a:link 保持原始颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆