Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> CSS

Vai trò bộ chọn :optional trong CSS

Bộ chọn :optional - Lặp lại

Nội dung trùng lặp với bài 1003062668. :optional chọn input không có required.

Ví dụ (giống hệt bài trước)

<!DOCTYPE html>
<html>
<head>
  <style>
    input:optional {
      background-color: blue;
    }
  </style>
</head>
<body>
  <form>
    Môn học: <input type="text" name="subject"><br>
    Sinh viên: <input type="text" name="student" required><br>
  </form>
</body>
</html>

Input "Môn học" (optional) → nền xanh.