开发者

How can I remove the underline of a link in chrome using CSS? [duplicate]

开发者 https://www.devze.com 2023-02-09 06:50 出处:网络
This question already has answers here: Underlining visited links (2 answers) Closed 8 years开发者_如何学C ago.
This question already has answers here: Underlining visited links (2 answers) Closed 8 years开发者_如何学C ago.

(it works in FF) How can I, using CSS, remove the underline of a visited link? I have tried:

a:visited {
    color: rgb(255, 255, 255);
    text-decoration: none !important;
}

and

a:visited {
    color: rgb(255, 255, 255);
    text-decoration: none;
}


The only CSS property you can apply on :visited links in most webkit-based browsers (like Chrome) is color. This is to prevent history stealing. Also, you can't determine the value of the color CSS property of links from JavaScript. See https://bugs.webkit.org/show_bug.cgi?id=24300 for details.

You can, however, change the style of all links with a{text-decoration: none;}. Here's a demo of the whole affair.


Some browser-vendors have decided/realised that separately styling a:visited hyperlinks represent a security/privacy threat to the user. Therefore some, though not all, have removed the ability to style a:visited differently.

I suspect that this is true of Chrome.

References:

  • http://djtechnocrat.blogspot.com/2010/12/browser-privacy-css-history-sniffing-in.html
  • http://blog.mozilla.com/security/2010/03/31/plugging-the-css-history-leak/
  • See also this Stackoverflow question: Google chrome a:visited background image not working


Your a:visited {} definition must come before your general a {} definition. You can use a:visited to set a color, but setting a text-decoration doesnt' work - but if you later set a general text-decoration for a elements, it does.

So:

a:visited {color: yellow;}
a {color:yellow; text-decoration: none; }

works (gives all links in yellow, no text decoration ever), but

a {color:yellow; text-decoration: none; }
a:visited {color: yellow;}

and

a {color:yellow; text-decoration: none; }
a:visited {color: yellow; text-decoration: none;}

don't (both give all links in yellow, but underlined)

0

精彩评论

暂无评论...
验证码 换一张
取 消