如何使用 CSS 選擇具有指定屬性的元素


要選擇具有屬性的元素,請使用 CSS [attribute] selector。

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

你可以嘗試執行以下程式碼來實現 CSS[attribute] selector,

示例

即時演示

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

更新於: 2020-06-23

145 瀏覽

開啟你的職業

完成課程並獲得認證

開始
廣告
© . All rights reserved.