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

Tạo kiểu cho input được chọn (checked) với CSS

Bộ chọn :checked

:checked áp dụng kiểu cho <input type="checkbox">, <input type="radio">, hoặc <option> trong <select> khi chúng được chọn.

Ví dụ minh họa

<!DOCTYPE html>
<html>
<head>
  <style>
    input:checked {
      height: 20px;
      width: 20px;
    }
  </style>
</head>
<body>
  <p>Môn thể thao yêu thích:</p>
  <form action="">
    <input type="checkbox" value="Football"> Bóng đá<br>
    <input type="checkbox" value="Cricket"> Cricket<br>
    <input type="checkbox" checked value="Tennis"> Tennis<br>
    <input type="checkbox" value="Badminton"> Cầu lông<br>
  </form>
</body>
</html>

Checkbox "Tennis" có sẵn checked → kích thước 20x20px. Người dùng tick các ô khác cũng sẽ áp dụng kiểu này.