css - 为什么我似乎无法将 :visited 和::after 结合起来?

标签 css css-selectors

我正在编写一些 CSS 来创建一些生成的内容。

.foo:visited::after {
  display: inline;
  content: " visited";
 }

但是,没有任何效果。

如果我将选择器更改为 .foo::after,它就可以工作。

同样,我的 .foo:visited 样式也生效。

Safari Web 检查器甚至显示了我的 :visited::after 样式,就好像它们已生效一样!

为什么我看不到生成的内容?

最佳答案

浏览器限制您可以在访问的链接上修改的样式,如果您使用 JavaScript 查询链接的当前颜色,浏览器甚至会对您撒谎。

为什么?

否则,您在 scumbag-advertising.example.com 上可以运行一堆 JavaScript 来查看浏览器历史记录中有哪些网站(或至少是 URL)!

有关更多信息,请参阅:visited on MDNthis longer explanation of how this privacy hole was closed :

Historically, the CSS :visited selector has been a way for sites to query the user's history, by using getComputedStyle() or other techniques to walk through the user's history to figure out what sites the user has visited. This can be done quickly, and makes it possible not only to determine where the user has been on the web, but can also be used to guess a lot of information about a user's identity.

几年前,浏览器通过限制更改和谎报颜色来修补这个漏洞。

关于css - 为什么我似乎无法将 :visited 和::after 结合起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36418460/

相关文章:

javascript - CKEditor - 反射(reflect)样式,也包括具有复杂选择器的样式

html - 嵌套表结构不正确

javascript - 如何改变小图片相对于大图片的位置?

javascript - 在移动设备上禁用静态固定导航栏脚本

html - CSS 选择器 - 如何选择第一个和最后一个 div

html - CSS last-child 不覆盖父边界

groovy - 在geb模块中查找直接子模块

css - Foundation Block Grid 和 nth-child 选择器

javascript - 如何将其转换为DataTable?

javascript - 在 CSS IE6 问题上需要帮助