用 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.com/videotutorials/images/tutor_connect_home.jpg" height = "200" width = "200">
      <img src = "https://tutorialspoint.com/videotutorials/images/tutorial_library_home.jpg" height = "200" width = "200" alt = "Tutorials Library">
   </body>
</html>

更新时间:24-6 月 -2020

1K+ 浏览

开启你的 职业生涯

完成课程获得认证

开始使用
广告
© . All rights reserved.