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 次瀏覽

開啟你的 職業生涯

完成課程即可取得認證

開始
廣告