Strange results with an empty href and the :link pseudo class

穿精又带淫゛_ 提交于 2019-12-05 01:44:13

This would appear to be due to the way individual browsers chose to handle unvisited links. The W3 spec (http://www.w3.org/TR/CSS2/selector.html#link-pseudo-classes) states:

The :link pseudo-class applies for links that have not yet been visited.

Chrome (and Opera) see href="" and href as being the current url and thus deem them as visited. Firefox and IE treat href="" and href as unvisited until you actually click on them.

IE (unclicked):

Chrome (unclicked):

To support this logic, adding a fifth link with href="http://stackoverflow.com/questions/30371788/strange-results-with-an-empty-href-and-the-link-pseudo-class" (this page) will result in a red link in Chrome (similar to the href="" and href links) because it sees the page as visited.

a {
  color: red;
}
a:link {
  color: green;
}
<a href="#">one</a>
<a href="">two</a>
<a href>three</a>
<a>four</a>
<a href="http://stackoverflow.com/questions/30371788/strange-results-with-an-empty-href-and-the-link-pseudo-class">five</a>
<a href="unvisited">six</a>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!