组合多个伪选择器 [英] Combining multiple pseudo-selectors

查看:187
本文介绍了组合多个伪选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,在一个时间点,组合多个伪选择器是可能的。例如,可以这样做:



a:visited:hover {color:red}



Google快速搜索会显示多个此类实例,此处此处这里。我无法在最新版本的Safari,Firefox或Chrome中使用此功能。

解决方案

:visited

code> pseudoclass不能用于大多数现代浏览器中的大多数样式,因为它是一个安全漏洞。有关更正式的讨论,请参见此链接



简短版本是,如果您可以以不同的方式设置:visited 链接,您可以使用它来确定访问了各种网站,因此根据他们的浏览器历史记录来定位他们。因此,大多数现代浏览器会严格限制可以对其进行的样式。



您仍然可以链接伪选择器。例如, a:focus:hover 只有在元素聚焦和悬浮时才能应用样式。请参见此链接进行演示。


It appears that at one point in time combining multiple pseudo-selectors was possible. For example, one could do this:

a:visited:hover {color: red}

A quick Google search reveals multiple examples of this in action, here, here, and here. I am unable to get this feature to work in the latest versions of Safari, Firefox, or Chrome. Can anyone explain why this feature has regressed and/or been handicapped?

解决方案

The :visited pseudoclass can't be used for most styling in a lot of modern browsers anymore because it's a security hole. See this link for a more formal discussion on it.

The short version is that if you can style :visited links differently, you can use that to determine if people have visited various sites, and therefore target them based on their browser history. Most modern browsers therefore heavily restrict the styling that can be done on them.

You can still chain pseudoselectors. For example, a:focus:hover works just fine to apply styles only if the element is focused AND hovered. See this link for a demonstration.

这篇关于组合多个伪选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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