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

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

Tạo kiểu cho input bị vô hiệu hóa

Bộ chọn :disabled chọn các phần tử form (input, button, select, textarea) có thuộc tính disabled.

Ví dụ minh họa

<!DOCTYPE html>
<html>
<head>
  <style>
    input:enabled  { background: blue; color: white; }
    input:disabled { background: red; color: white; }
  </style>
</head>
<body>
  <form action="">
    Môn học: <input type="text" name="subject"><br>
    Sinh viên: <input type="text" name="student"><br>
    Tuổi: <input type="number" name="age" disabled><br>
  </form>
</body>
</html>

Ô "Tuổi" có disabled → nền đỏ. Các ô còn lại :enabled (mặc định) → nền xanh. Giúp người dùng nhận biết trường không thể nhập.