我正在编写一些 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 MDN和 this 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 usinggetComputedStyle()
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/