Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

จัดสไตล์อินพุตที่ไม่มี required ด้วย CSS


Pseudo-class :optional

ใช้ :optional เลือก <input> ที่ ไม่มี แอตทริบิวต์ required

ตัวอย่าง

<!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>