用 CSS 選中所有帶 alt 屬性的元素


要使用屬性選擇一個元素,用 CSS [attribute] 選擇器。

例如,alt 屬性或 target 屬性等等。

你可以嘗試執行下面的程式碼來實現 CSS[attribute] 選擇器,

示例

線上演示

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

更新時間:24-6 月 -2020

1K+ 瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始使用
廣告
© . All rights reserved.