Reputation: 26281
Is it possible to use CSS to make an element the same color as the default <a>
color?
If so, how?
Upvotes: 0
Views: 150
Reputation: 63317
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);
}
Then you can apply the class defaultLinkColor
for your element:
<span class='defaultLinkColor'>I'm not a link</span>
Upvotes: 2