CSS 中的 :any-link 伪类表示一个元素,该元素是超链接的源锚点,无论它是否已被访问过。因此,它匹配所有具有 href 属性的 <a> 或 <area> 元素。简而言之,它还匹配与 :link 或 :visited 匹配的所有元素。
这在 Safari 浏览器上不受支持。
语法
:any-link {
/* ... */
}
CSS的 ;any-link 示例
以下示例演示了 :any-link 伪类的用法,该伪类与 :hover 一起使用,它会在悬停时更改链接文本的颜色。
通过 :any-link 伪类的样式不会应用于没有 href 属性的锚元素。
<html>
<head>
<style>
div {
padding: 5px;
border: 2px solid black;
margin: 1em;
width: 500px;
}
a:any-link {
font-weight: 900;
text-decoration: none;
color: green;
font-size: 1em;
}
.with-nohref {
color: royalblue;
}
:any-link:hover {
color: crimson;
}
</style>
</head>
<body>
<h3>:any-link example</h3>
<div>
anchor elements with href to tutorialspoint.com--
<a href="https://tutorialspoint.com">click here</a>
</div>
<div>
<a class="with-nohref">with no href</a>
</div>
<div>
<a href="" class="">with empty href</a>
</div>
</body>
</html>