Home >Web Front-end >CSS Tutorial >Why Do My Visited Links Remain Bold in IE and Chrome?

Why Do My Visited Links Remain Bold in IE and Chrome?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-24 22:02:17720browse

Why Do My Visited Links Remain Bold in IE and Chrome?

Why :visited CSS Style Stays Bold in IE and Chrome

In a given HTML document, users often encounter a link that maintains its bold formatting even after being visited. This issue arises in browsers like Internet Explorer and Chrome. Let's delve into the root of this problem.

The HTML and CSS code under scrutiny is:

<html>
    <head>
        <style>
            A {font-weight: bold; color:black;}
            A:visited {font-weight: normal; color: black; }
            .Empty {font-weight: bold; color: black; }
        </style>
    </head>
    <body>
        <a href="http://mysite">click me</a>
    </body>
</html>

Typically, upon visiting a link, the :visited pseudoclass should alter its appearance, but in this case, font-weight remains bold.

Security Feature Restriction

The culprit behind this behavior is a security measure implemented in modern browsers like Firefox 4, Internet Explorer 9, and Chrome. This restriction prevents CSS exploits that could arise from modifying the font weight of visited links.

GetComputedStyle() Behavior

In these browsers, getComputedStyle() generally returns values for visited links as though they had not been visited. However, malicious actors could potentially exploit this by changing the element's width using font-weight. Therefore, allowing font-weight changes for :visited links could compromise the security measure.

Browser Safeguards

To thwart CSS exploits, browsers employ specific safeguards:

  • getComputedStyle() always indicates that links have never been visited.
  • Sibling selectors (e.g., :visited span) render adjacent elements as unvisited.
  • In rare cases involving nested links, the targeted element may also be rendered as unvisited.

Conclusion

This restriction is a security feature aimed at protecting against CSS exploits. Unfortunately, there is no known workaround to modify :visited font-weight in Internet Explorer and Chrome.

The above is the detailed content of Why Do My Visited Links Remain Bold in IE and Chrome?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn