問題描述
是否可以將 background-image: 屬性添加到訪問的鏈接?
Is it possible to add the background-image: property to visited links?
a.coolLinks:visited{
background-image:url("http://www.ledr.com/colours/black.jpg");
}
謝謝
所以這似乎是一個安全漏洞,這就是它無法完成的原因.沒有跡象表明瀏覽器阻止了這種 CSS 樣式.
So it appears that this is a security vulnerability and this is why it cannot be done. There was no indication that the browsers were blocking this css style.
推薦答案
根據大多數規范,您的代碼是正確的.但是,許多瀏覽器會考慮訪問鏈接上的背景圖片可能侵犯用戶隱私,所以他們不允許這樣做.
Your code is correct according to most specifications. However, many browsers consider background images on visited links a potential violation of user's privacy, so they do not allow it.
觀察這個例子:
<p><a href="/unvisited">Unvisited link</a></p>
<p><a >Visited Link</a></p>
<style>
a {
background:red url("http://placekitten.com/100/101?image=2") center center no-repeat;
display: block;
height: 200px;
width: 200px;
overflow: hidden;
text-align: center;
background-color: red;
}
a:visited {
background:blue url("http://placekitten.com/100/100?image=1") center center no-repeat;
}
</style>
(也位于 http://jsfiddle.net/Yq5GY/1/).Firefox 忽略訪問鏈接的背景圖像聲明,并且從不顯示獨奏小貓.您可以使用背景顏色進行一些區分.無論如何,僅依賴圖像的可用性很差.
(Also at http://jsfiddle.net/Yq5GY/1/). Firefox ignores the background image declaration for visited links, and never displays the solo kitten. You can do some differentiation with background color. It's bad usability to rely on images alone, anyhow.
這篇關于背景圖像:for :visited links?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!