如何透過 CSS 選擇包含特定單詞的屬性值的元素?


使用 [attribute ~= "value"] 選擇器透過 CSS 選擇包含特定單詞的屬性值的元素。

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

示例

現場演示

<!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>

已更新於: 2020-6-24

197 次瀏覽

開始您的 職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.