:any-link

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流瀏覽器均已支援。

:any-link CSS 偽類選擇器表示一個元素,該元素充當超連結的源錨點,而不管它是否已被訪問。換句話說,它匹配所有具有 href 屬性的 <a><area> 元素。因此,它匹配所有與 :link:visited 匹配的元素。

試一試

p {
  font-weight: bold;
}

a:any-link {
  color: forestgreen;
  text-decoration-color: hotpink;
}
<p>Pages that you might have visited:</p>
<ul>
  <li>
    <a href="https://mdn.club.tw">MDN Web Docs</a>
  </li>
  <li>
    <a href="https://www.youtube.com/YouTube">Google</a>
  </li>
</ul>
<p>Pages unlikely to be in your history:</p>
<ul>
  <li>
    <a href="https://mdn.club.tw/missing-3">Random MDN page</a>
  </li>
  <li>
    <a href="https://example.com/missing-3">Random Example page</a>
  </li>
</ul>

語法

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

示例

HTML

html
<a href="https://example.com">External link</a><br />
<a href="#">Internal target link</a><br />
<a>Placeholder link (won't get styled)</a>

CSS

css
a:any-link {
  border: 1px solid blue;
  color: orange;
}

/* WebKit browsers */
a:-webkit-any-link {
  border: 1px solid blue;
  color: orange;
}

結果

規範

規範
選擇器 Level 4
# the-any-link-pseudo

瀏覽器相容性

另見