: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>Pages that you might have visited:</p>
<ul>
  <li>
    <a href="https://developer.mozilla.org">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://developer.mozilla.org/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">外部链接</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…