CSS :optional 選擇器的作用


使用 CSS :optional 選擇器為沒有 “required” 特性的 <input> 元素設定樣式

示例

你可以嘗試執行以下程式碼來實現 :optional 選擇器

線上演示

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

更新於: 2020 年 7 月 1 日

154 次瀏覽

開啟你的 事業

完成學習課程,獲得認證

立即開始
廣告
© . All rights reserved.