:any-link
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2020年1月.
:any-link は CSS の擬似クラスセレクターで、訪問の有無とは独立したソースアンカーとして振る舞う要素を表します。言い換えれば、 href 属性を持つすべての <a> または <area> 要素を選択します。つまり、 :link または :visited に一致するすべての要素を選択します。
試してみましょう
p {
font-weight: bold;
}
a:any-link {
color: forestgreen;
text-decoration-color: hotpink;
}
<p>訪問済みの可能性のあるページ:</p>
<ul>
<li>
<a href="https://big.rakal.top">MDN Web Docs</a>
</li>
<li>
<a href="https://www.youtube.com/YouTube">Google</a>
</li>
</ul>
<p>履歴にない可能性が高いページ:</p>
<ul>
<li>
<a href="https://big.rakal.top/missing-3">ランダム MDN ページ</a>
</li>
<li>
<a href="https://example.com/missing-3">ランダム Example ページ</a>
</li>
</ul>
構文
css
:any-link {
/* ... */
}
例
>HTML
html
<a href="https://example.com">外部リンク</a><br />
<a href="#">内部ターゲットリンク</a><br />
<a>プレースホルダーリンク(スタイルは適用されません)</a>
CSS
css
a:any-link {
border: 1px solid blue;
color: orange;
}
/* WebKit ブラウザー向け */
a:-webkit-any-link {
border: 1px solid blue;
color: orange;
}
結果
仕様書
| Specification |
|---|
| Selectors Level 4> # the-any-link-pseudo> |
ブラウザーの互換性
Loading…