如何使用 CSS 來選擇標籤中的屬性值含有指定單詞的元素?


使用 [attribute ~= "value"] 選擇器,以便使用 CSS 來選擇標籤中的屬性值含有指定單詞的元素。

你可以嘗試執行以下程式碼,實現 [attribute ~= "value"] 選擇器。我們在此搜尋的單詞是 “Tutorials”(教程)

示例

線上演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         [alt ~= Tutorials] {
            border: 5px solid orange;
            border-radius: 5px;
         }
      </style>
   </head>
   <body>
      <img src = "https://tutorialspoint.tw/videotutorials/images/tutor_connect_home.jpg" height = "200" width = "200" alt = "Tutor Connect">
      <img src = "https://tutorialspoint.tw/videotutorials/images/tutorial_library_home.jpg" height = "200" width="200" alt = "Tutorials Library">
   </body>
</html>

更新日期: 24-6 月-2020

197 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.