Home >Web Front-end >CSS Tutorial >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:
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!