CSS:link和:visited伪类 - 是web浏览器遵守规范? [英] CSS :link and :visited pseudo-classes - are web browsers adhering to the spec?

查看:135
本文介绍了CSS:link和:visited伪类 - 是web浏览器遵守规范?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

W3.org CSS规格说明以下(强调我):



  • 链接伪类适用于尚未访问的链接



$ b

这两种状态是互斥


这意味着应用于:link 选择器应该只应用于未访问的链接。但是,这种情况的唯一属性似乎是 color 。将字体大小,背景等应用于:link 选择器定位所有链接。



页面上显示:


注意。样式表作者可以滥用:link和:被访问的伪类来确定用户在没有用户同意的情况下访问了哪些网站。



UA因此可以处理所有链接作为未访问的链接,或实施其他措施以保持用户的隐私,同时呈现访问和未访问的链接不同。


因为我知道这只适用于JavaScript返回的样式,而不是样式本身的显示。



这是一个JS小提琴显示的问题。

解决方案

这行,

因此,UA可以将所有链接视为未访问的链接,或者实现其他措施以在呈现访问链接和未访问链接时保持用户的隐私。


不适用于由JavaScript返回的样式—它正是它的声音。这意味着浏览器可能完全忽略:visited 上的某些属性(这是这种情况下发生的)。由于 font-size 会增加包含元素的大小,因此允许:visited 链接的属性不同将破坏浏览器实现的其他安全措施。



浏览器可以选择重新计算尺寸,而不应用:visited 如果它想。自然,这是更多的工作,更少的性能比只是不允许某些属性。很明显,该决定是基于这样的事实做出的,即实际上不需要使用不同的字体大小,背景等来区分访问链接和未访问链接,并且通常大多数开发人员将坚持仅仅稍微修改颜色。



没有,他们没有偏离规格,他们利用了允许的例外。


The W3.org CSS specification states the following (emphasis mine):

  • The :link pseudo-class applies for links that have not yet been visited.
  • The :visited pseudo-class applies once the link has been visited by the user.

The two states are mutually exclusive.

This means that any style applied to the :link selector should only be applied to unvisited links. However, the only property for which this is true appears to be color. Applying font sizes, backgrounds and so on to the :link selector targets all links.

There is a note further down the page that states:

Note. It is possible for style sheet authors to abuse the :link and :visited pseudo-classes to determine which sites a user has visited without the user's consent.

UAs may therefore treat all links as unvisited links, or implement other measures to preserve the user's privacy while rendering visited and unvisited links differently.

However, as far as I'm aware this only applies to the styles returned by Javascript, not to the display of the styles themselves.

Here's a JS fiddle showing the issue. Are the browsers deviating from the spec here, or is there something I'm missing?

解决方案

The line,

"UAs may therefore treat all links as unvisited links, or implement other measures to preserve the user's privacy while rendering visited and unvisited links differently."

Isn't applicable to styles returned by JavaScript only — it is exactly as it sounds. This means that browsers may just ignore certain properties on :visited entirely (which is what's happening in this case). Since the font-size would increase the size of the containing element, allowing the property to be different for :visited links would undermine the other security measures implemented by the browser.

A browser could choose to recalculate the dimensions without the :visited styles applied, if it wanted to. Naturally, this is more work and less performant than just disallowing certain properties. It's clear that the decision has been made based on the fact that there is no real need to use different font sizes, backgrounds, etc to differentiate between visited and unvisited links and, generally, most developers will stick to just modifying the colour slightly.

So no, they're not deviating from the spec, they're taking advantage of a permissible exception.

这篇关于CSS:link和:visited伪类 - 是web浏览器遵守规范?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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