使元素与默认锚链接相同的颜色 [英] Make element same color as default anchor link

查看:109
本文介绍了使元素与默认锚链接相同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用CSS将元素设置为与默认< a> 颜色相同的颜色?

Is it possible to use CSS to make an element the same color as the default <a> color?

如果是,如何?

推荐答案

我认为没有关键字将颜色指定为同一颜色的链接(虽然我们确实有关键字指定系统颜色)。只有一个解决方法是使用脚本来构建一些CSS规则样式的颜色与链接相同,并为您的元素使用此样式。

I think there is no keyword to specify a color as the same color of a link (although we does have keywords to specify system colors). There is only a workaround is using a script to build some CSS rule styling the color the same as of a link and use this style for your element.

//Get the default link color in the current browser
var a = $("<a href='#'>").appendTo('body');
var linkColor = a.css('color');
a.remove();
//build the CSS rule 
var ss = document.styleSheets[0];
if('addRule' in ss) {
  ss.addRule(".defaultLinkColor", "color: " + linkColor);
} else if('insertRule' in ss){
  ss.insertRule(".defaultLinkColor { color: " + linkColor + ";}", 0);  
}

然后,您可以应用 defaultLinkColor 为您的元素:

Then you can apply the class defaultLinkColor for your element:

<span class='defaultLinkColor'>I'm not a link</span>

这篇关于使元素与默认锚链接相同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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