首頁  >  文章  >  web前端  >  CSS 的作用:目標選擇器

CSS 的作用:目標選擇器

王林
王林轉載
2023-09-08 09:33:09623瀏覽

CSS 的作用:目标选择器

使用 CSS :target 選擇器透過 CSS 突出顯示活動的 HTML 錨點。

範例

您可以嘗試執行以下程式碼來實作 :target 選擇器

現場示範

<!DOCTYPE html>
<html>
   <head>
      <style>
         :target {
            border: 2px solid #D4D4D4;
            background-color: orange;
            color: white;
         }
      </style>
   </head>
   <body>
      <p>Click any of the subject below.</p>
      <p><a href = "#tut1">Maths</a></p>
      <p><a href = "#tut2">Java</a></p>
      <p><a href = "#tut3">C++</a></p>
      <p><a href = "#tut4">C</a></p>
      <p>This is demo text.</p>
      <p>This is demo text.</p>
      <p>This is demo text.</p>
      <p>This is demo text.</p>
      <p>This is demo text.</p>
      <p id = "tut1"><b>Maths Tutorial</b></p>
      <p id = "tut2"><b>Java Tutorial</b></p>
      <p id = "tut3"><b>C++ Tutorial</b></p>
      <p id = "tut4"><b>C Tutorial</b></p>
   </body>
</html>

以上是CSS 的作用:目標選擇器的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除