CSS - 偽類 :any-link



CSS 中的:any-link偽類表示超連結的源錨元素,無論它是否已被訪問過。因此,它匹配所有具有href屬性的<a><area>元素。簡而言之,它也匹配所有匹配:link:visited的元素。

Safari 瀏覽器不支援此功能。

語法

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

CSS :any-link 示例

以下示例演示了:any-link偽類的用法,與:hover一起使用,在懸停時更改連結文字的顏色。

對於沒有 href 屬性的錨元素,:any-link偽類樣式不會應用。

<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.tw">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>
廣告

© . All rights reserved.