使用 CSS 样式化已聚焦的元素

cssweb developmentfront end technology更新于 2025/5/10 3:56:17

要选择已聚焦的元素,请使用 :focus 选择器。您可以尝试运行以下代码来实现 :focus 选择器−

示例

<!DOCTYPE html>
<html>
   <head>
      <style>
         input:focus {
            background-color: green;
         }
      </style>
   </head>
   <body>
      <form action = "">
         Subject <input type = "text" name = "subject"><br>
         Student: <input type = "text" name = "student"><br>
         Age: <input type = "number" name" = age><br>
         <input type = "submit" value="Submit">
      </form>
   </body>
</html>

相关文章


有用资源