为什么 a:visited css 样式不起作用? [英] Why doesn't this a:visited css style work?

查看:45
本文介绍了为什么 a:visited css 样式不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何原因无法在 Internet Explorer 或 Chrome 上运行:

Is there any reason why this does not work on Internet Explorer or Chrome:

<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>

我点击的链接永远不会正常,只是保持粗体.在某些其他浏览器上它可以工作.

The link I click never goes to normal and just stays bold. On some other browsers it works.

改变大小写并没有影响它.将 a 更改为 a:link 并没有影响它.更改颜色有效,只是字体粗细无效.

Changing case did not affect it. Changing a to a:link did not affect it. Changing color works, just not font-weight.

一种解决方法是更改​​可访问性以忽略网页颜色.我无法访问源代码,所以我必须这样做.

One workaround was to change accessibility to ignore web colors. I do not have access to the source, so I had to do it this way.

推荐答案

实际上,这与区分大小写无关.这是一项安全功能.:visited 伪类的功能在许多现代浏览器(Fx4、IE9、Chrome)中受到限制,以防止 CSS 漏洞:阅读有关它此处.

Actually, this has nothing to do with case sensitivity. This is a security feature. The functionality of :visited pseudoclass has been restricted in many modern browsers (Fx4, IE9, Chrome) to prevent CSS exploit: read about it here.

如今,这些浏览器中的 getComputedStyle() 通常返回访问过的链接的值,就好像它们未被访问过一样.但是,我可以简单地想象一下绕过这个:对访问过的链接使用 font-weight,元素的宽度会发生变化,因此浏览器将允许更改 font-weight:访问过的 链接实际上并不能修复安全漏洞.

Nowadays, getComputedStyle() in these browsers usually returns values for visited links as if they weren't visited. However, I can simply imagine circumventing of that: using font-weight for visited links, the element's width changes so browsers that would allow changing font-weight for :visited links wouldn't actually fix the security hole.

你可以看到一些具体的事情 浏览器可以防止这种情况发生:

You can see there are some specific things browsers do to protect against this:

  • window.getComputedStyle 方法以及类似的函数(例如 element.querySelector)将始终返回值,表明用户从未访问过页面上的任何链接.
  • 如果您使用诸如 :visited + span 之类的同级选择器,则相邻元素(在此示例中为 span)的样式将与未访问链接一样.
  • 在极少数情况下,如果您使用嵌套链接元素并且匹配的元素与其在历史记录中的存在性正在测试的链接不同,则该元素也将呈现为好像该链接未被访问过一样.
  • The window.getComputedStyle method, and similar functions such as element.querySelector, will always return values indicating that a user has never visited any of the links on a page.
  • If you use a sibling selector such as :visited + span, the adjacent element (span in this example) will be styled as if the link were unvisited.
  • In rare scenarios, if you're using nested link elements and the element being matched is different from the link whose presence in history is being tested, the element will be rendered as if the link were unvisited, as well.

因此,此问题没有解决方法.

Thus, there's no workaround for this issue.

这篇关于为什么 a:visited css 样式不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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