:local-link

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

:local-link CSS 伪类表示指向同一文档的链接。因此,它是超链接的源锚点,其目标的绝对 URL 与该元素的文档 URL 匹配。

css
/* Selects any <a> that links to the current document */
a:local-link {
  color: green;
}

语法

css
:local-link {
  /* ... */
}

示例

HTML

html
<a href="#target">This is a link on the current page.</a><br />
<a href="https://example.com">This is an external link</a><br />

CSS

css
a:local-link {
  color: green;
}

结果

规范

规范
选择器 Level 4
# local-link-pseudo

浏览器兼容性

目前没有浏览器支持此功能。

另见