:link - CSS: Cascading Style Sheets 编辑

The :link CSS pseudo-class represents an element that has not yet been visited. It matches every unvisited <a>, <area>, or <link> element that has an href attribute.

/* Selects any <a> that has not been visited yet */
a:link {
  color: red;
}

Styles defined by the :link pseudo-class will be overridden by any subsequent link-related pseudo-class (:active, :hover, or :visited) that has at least equal specificity. To style links appropriately, put the :link rule before all other link-related rules, as defined by the LVHA-order: :link:visited:hover:active.

Note: Use :any-link to select an element independent of whether it has been visited or not.

Syntax

:link

Examples

By default, most browsers apply a special color value to visited links. Thus, the links in this example will probably have special font colors only before you visit them. (After that, you'll need to clear your browser history to see them again.) However, the background-color values are likely to remain, as most browsers do not set that property on visited links by default.

HTML

<a href="#ordinary-target">This is an ordinary link.</a><br>
<a href="">You've already visited this link.</a><br>
<a>Placeholder link (won't get styled)</a>

CSS

a:link {
  background-color: gold;
  color: green;
}

Result

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of ':link' in that specification.
Living Standard
Selectors Level 4
The definition of ':link' in that specification.
Working DraftNo change.
Selectors Level 3
The definition of ':link' in that specification.
RecommendationNo change.
CSS Level 2 (Revision 1)
The definition of ':link' in that specification.
RecommendationLift the restriction to only apply it for <a> element.
CSS Level 1
The definition of ':link' in that specification.
RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:114 次

字数:5353

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文