样式具有“必需”属性的元素


使用 CSS:必需选择器来设定样式,使具有“必需”属性的 <input> 元素美化。

示例

您可以尝试运行以下代码来实现:必需选择器

实时演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         input:required {
            background-color: orange;
         }
      </style>
   </head>
   <body>
      <form>
         Subject: <input type = "text" name = "subject" value = "C++"><br>
         Student: <input type = "text" name = "student" value = "Amit" required><br>
      </form>
   </body>
</html>

更新于: 2020-07-01

388 次浏览

开始您的 职业生涯

通过完成该课程获得认证

开始学习
广告
© . All rights reserved.