s42*_*427 5 html css css-selectors pseudo-class
我知道:link允许选择未访问的元素,并且我知道LoVe-HAte 技巧可以记住放置各种链接伪类的顺序。但在实践中,我总是这样设计链接:
a {
/* common styles for all links, regardless of state */
/* this includes unvisited links, and thus a:link */
}
a:visited {
/* specific styles for visited links */
}
a:hover {}
a:active {}
Run Code Online (Sandbox Code Playgroud)
由于链接要么被访问,要么未被访问,这涵盖了所有可能的情况,我真的不明白:link伪类添加到表中的内容。
我错过了什么吗?
选择a:link器允许您设置<a>实际链接到某处的标签的样式。
传统上,没有属性的裸<a>标签href用作文档中的标记;将位置设置为document.html#foo将跳转到<a id="foo">文档中的任意位置。毕竟,它被称为“锚”标签是有原因的。
传统的 HTML 可能看起来像这样:
a {
color: green;
}
a:link {
color: red;
}Run Code Online (Sandbox Code Playgroud)
<h2>Navigation</h2>
<a href="#ch1">Chapter 1 (red :link)</a>
...
<h3><a id="ch1">Chapter 1 (green anchor)</a></h3>
<p>It was the best of times...</p>Run Code Online (Sandbox Code Playgroud)
后续的 HTML 标准允许您使用document.html#thing语法跳转到具有 属性 的任何元素id="thing",但情况并非总是如此。