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

Tạo kiểu cho input enabled với CSS

Bộ chọn :enabled

:enabled chọn các phần tử form **không bị vô hiệu hóa** (không có thuộc tính disabled). Đây là trạng thái mặc định.

Ví dụ minh họa

<!DOCTYPE html>
<html>
<head>
  <style>
    input:enabled {
      background: blue;
      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>

Hai ô đầu (enabled) → nền xanh, chữ trắng. Ô "Tuổi" (disabled) → không ảnh hưởng bởi quy tắc này.