CSS cho đầu vào

Lưu ý rằng chúng tôi đã đặt thuộc tính


input[type=text] {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
}
8 thành

input[type=text] {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
}
9. Điều này chắc chắn rằng phần đệm và đường viền cuối cùng được bao gồm trong tổng chiều rộng và chiều cao của các thành viên

Định dạng đường viền cho trường đầu vào

Sử dụng thuộc tính


input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
0 để thay đổi kích thước và màu sắc đường viền, và sử dụng thuộc tính

input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
1 để bo tròn
CSS cho đầu vào
CSS cho đầu vào


input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}


Nếu bạn chỉ muốn thêm đường viền bên dưới, hãy sử dụng thuộc tính


input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
2
CSS cho đầu vào
CSS cho đầu vào


input[type=text] {
  border: none;
  border-bottom: 2px solid red;
}

Định dạng màu cho trường đầu vào

Sử dụng thuộc tính


input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
3 để thêm màu nền cho trường bắt đầu và thuộc tính

input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
4 thay đổi màu văn bản
CSS cho đầu vào
CSS cho đầu vào


input[type=text] {
  background-color: #3CBC8D;
  color: white;
}

Create a object for the start field

Mặc định, một số trình duyệt sẽ thêm đường viền màu xanh xung quanh trường bắt đầu khi người dùng nhấp chuột để nhập thông tin. Bạn có thể xóa trạng thái này bằng cách thêm


input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
5 cho trường đầu vào
Use the selector. tiêu điểm để làm điều gì đó với trường bắt đầu khi nhấp chuột để nhập thông tin
Ví dụ 1


input[type=text]:focus {
  background-color: lightblue;
}


Ví dụ 2


input[type=text]:focus {
  border: 3px solid #555;
}

Thêm biểu tượng/hình ảnh vào bên trong trường đầu vào

Nếu bạn muốn có biểu tượng bên trong trường bắt đầu vào, hãy sử dụng thuộc tính


input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
6 và thuộc tính vị trí

input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
7. cũng lưu ý rằng chúng ta thêm khoảng trống bên trái để dành không gian cho biểu tượng
CSS cho đầu vào
CSS cho đầu vào


input[type=text] {
  background-color: white;
  background-image: url('searchicon.png');
  background-position: 10px 10px;
  background-repeat: no-repeat;
  padding-left: 40px;
}

Thêm hiệu ứng tìm kiếm cho trường bắt đầu vào

Trong ví dụ này, chúng ta sử dụng thuộc tính


input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
8 trong CSS để tạo hiệu ứng chiều rộng cho trường tìm kiếm khi người dùng nhấp chuột vào trường nhập và bản


input[type=text] {
  transition: width 0.4s ease-in-out;
}

input[type=text]:focus {
  width: 100%;
}

Create type for Textareas

Chú thích. Sử dụng thuộc tính


input[type=text] {
  border: 2px solid red;
  border-radius: 4px;
}
9 để ngăn các vùng văn bản bị thay đổi kích thước (tắt “grabber” ở góc dưới cùng bên phải)

Các phần tử thuộc loại checkbox được hiển thị theo mặc định dưới dạng hộp được chọn (đánh dấu) khi được kích hoạt, giống như bạn có thể thấy trong biểu mẫu giấy tờ chính thức của chính phủ. Giao diện chính xác phụ thuộc vào cấu hình hệ điều hành mà trình duyệt đang chạy. Nói chung đây là một hình vuông nhưng nó có thể có các góc tròn. Một hộp kiểm cho phép bạn chọn các giá trị đơn lẻ để gửi trong một biểu mẫu (hoặc không)

Ghi chú. Các nút chọn tương tự như hộp kiểm, nhưng có một điểm khác biệt quan trọng — các nút chọn được nhóm thành một bộ trong đó chỉ có thể chọn một nút chọn tại một thời điểm, trong khi các hộp kiểm cho phép bạn bật và tắt các giá trị đơn lẻ. Khi có nhiều điều khiển, các nút radio cho phép chọn một trong số tất cả các điều khiển đó, trong khi các hộp kiểm cho phép chọn nhiều giá trị

Một chuỗi đại diện cho giá trị của hộp kiểm. Điều này không được hiển thị ở phía máy khách, nhưng trên máy chủ, đây là

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
0 được cung cấp cho dữ liệu được gửi cùng với hộp kiểm của
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
1. Lấy ví dụ sau

<form>
  <div>
    <input
      type="checkbox"
      id="subscribeNews"
      name="subscribe"
      value="newsletter" />
    <label for="subscribeNews">Subscribe to newsletter?label>
  div>
  <div>
    <button type="submit">Subscribebutton>
  div>
form>

Trong ví dụ này, chúng ta có tên là

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
2 và giá trị là
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
3. Khi biểu mẫu được gửi, cặp tên/giá trị dữ liệu sẽ là
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
4

Nếu thuộc tính

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
0 bị bỏ qua, giá trị mặc định cho hộp kiểm là
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
6, vì vậy dữ liệu đã gửi trong trường hợp đó sẽ là
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
7

Note: If a checkbox is unchecked when its form is submitted, there is no value submitted to the server to represent its unchecked state (e.g.

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
8); the value is not submitted to the server at all. If you wanted to submit a default value for the checkbox when it is unchecked, you could include an inside the form with the same
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
1 and
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
0, generated by JavaScript perhaps.

Ngoài các thuộc tính chung được chia sẻ bởi tất cả các phần tử , đầu vào "checkbox" hỗ trợ các thuộc tính sau

Thuộc tính Boolean cho biết hộp kiểm này có được chọn theo mặc định hay không (khi tải trang). Nó không cho biết liệu hộp kiểm này hiện có được chọn hay không. nếu trạng thái của hộp kiểm bị thay đổi, thuộc tính nội dung này không phản ánh sự thay đổi. (Chỉ thuộc tính IDL của

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" checked />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
4 của
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" checked />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
3 được cập nhật. )

Ghi chú. Không giống như các điều khiển đầu vào khác, giá trị của hộp kiểm chỉ được bao gồm trong dữ liệu đã gửi nếu hộp kiểm hiện tại là

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" checked />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
3. Nếu đúng như vậy, thì giá trị của thuộc tính
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
0 của hộp kiểm được báo cáo là giá trị của đầu vào. Không giống như các trình duyệt khác, Firefox theo mặc định duy trì trạng thái được kiểm tra động của một khi tải trang. Sử dụng thuộc tính để kiểm soát tính năng này

Thuộc tính

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
0 là thuộc tính mà tất cả các chia sẻ; . khi một biểu mẫu được gửi, chỉ các hộp kiểm hiện đang được chọn mới được gửi tới máy chủ và giá trị được báo cáo là giá trị của thuộc tính
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
0. Nếu
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
0 không được chỉ định khác, thì đó là chuỗi
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
6 theo mặc định. Điều này đã được chứng minh ở phần trên

Chúng tôi đã đề cập đến cách sử dụng hộp kiểm cơ bản nhất ở trên. Bây giờ chúng ta hãy xem các tính năng và kỹ thuật phổ biến khác liên quan đến hộp kiểm mà bạn sẽ cần

Ví dụ chúng ta thấy ở trên chỉ chứa một hộp kiểm; . Nếu chúng hoàn toàn không liên quan, thì bạn có thể giải quyết chúng một cách riêng biệt, như được hiển thị ở trên. Tuy nhiên, nếu tất cả chúng đều có liên quan với nhau thì mọi chuyện không đơn giản như vậy

Ví dụ: trong bản demo sau, chúng tôi bao gồm nhiều hộp kiểm để cho phép người dùng chọn sở thích của họ (xem phiên bản đầy đủ trong phần)

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>

Trong ví dụ này, bạn sẽ thấy rằng chúng tôi đã đánh dấu cho mỗi hộp kiểm giống nhau

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
1. Nếu cả hai hộp kiểm đều được chọn và sau đó biểu mẫu được gửi, bạn sẽ nhận được một chuỗi các cặp tên/giá trị được gửi như thế này.
inputInstance.indeterminate = true;
8. Khi chuỗi này đến máy chủ, bạn cần phân tích cú pháp chuỗi đó chứ không phải dưới dạng một mảng kết hợp, vì vậy tất cả các giá trị, không chỉ giá trị cuối cùng, của
inputInstance.indeterminate = true;
9 đều được ghi lại. Đối với một kỹ thuật được sử dụng với Python, hãy xem Xử lý nhiều hộp kiểm với một biến phía máy chủ, chẳng hạn

Để làm cho hộp kiểm được chọn theo mặc định, bạn đặt cho nó thuộc tính

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" checked />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
3. Xem ví dụ bên dưới

<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" checked />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>

Trong các ví dụ trên, bạn có thể nhận thấy rằng bạn có thể chuyển đổi một hộp kiểm bằng cách nhấp vào phần tử

const overall = document.querySelector('#enchantment');
const ingredients = document.querySelectorAll('ul input');

overall.addEventListener('click', (e) => {
  e.preventDefault();
});

for (const ingredient of ingredients) {
  ingredient.addEventListener('click', updateDisplay);
}

function updateDisplay() {
  let checkedCount = 0;
  for (const ingredient of ingredients) {
    if (ingredient.checked) {
      checkedCount++;
    }
  }

  if (checkedCount === 0) {
    overall.checked = false;
    overall.indeterminate = false;
  } else if (checkedCount === ingredients.length) {
    overall.checked = true;
    overall.indeterminate = false;
  } else {
    overall.checked = false;
    overall.indeterminate = true;
  }
}
1 được liên kết của nó cũng như trên chính hộp kiểm đó. Đây là một tính năng thực sự hữu ích của nhãn biểu mẫu HTML giúp dễ dàng nhấp vào tùy chọn bạn muốn, đặc biệt là trên các thiết bị màn hình nhỏ như điện thoại thông minh

Ngoài khả năng truy cập, đây là một lý do chính đáng khác để thiết lập đúng các yếu tố

const overall = document.querySelector('#enchantment');
const ingredients = document.querySelectorAll('ul input');

overall.addEventListener('click', (e) => {
  e.preventDefault();
});

for (const ingredient of ingredients) {
  ingredient.addEventListener('click', updateDisplay);
}

function updateDisplay() {
  let checkedCount = 0;
  for (const ingredient of ingredients) {
    if (ingredient.checked) {
      checkedCount++;
    }
  }

  if (checkedCount === 0) {
    overall.checked = false;
    overall.indeterminate = false;
  } else if (checkedCount === ingredients.length) {
    overall.checked = true;
    overall.indeterminate = false;
  } else {
    overall.checked = false;
    overall.indeterminate = true;
  }
}
1 trên biểu mẫu của bạn

Ngoài các trạng thái được chọn và không được chọn, có một trạng thái thứ ba mà một hộp kiểm có thể ở. không xác định. Đây là trạng thái không thể nói mục đó được bật hay tắt. Điều này được đặt bằng thuộc tính

const overall = document.querySelector('#enchantment');
const ingredients = document.querySelectorAll('ul input');

overall.addEventListener('click', (e) => {
  e.preventDefault();
});

for (const ingredient of ingredients) {
  ingredient.addEventListener('click', updateDisplay);
}

function updateDisplay() {
  let checkedCount = 0;
  for (const ingredient of ingredients) {
    if (ingredient.checked) {
      checkedCount++;
    }
  }

  if (checkedCount === 0) {
    overall.checked = false;
    overall.indeterminate = false;
  } else if (checkedCount === ingredients.length) {
    overall.checked = true;
    overall.indeterminate = false;
  } else {
    overall.checked = false;
    overall.indeterminate = true;
  }
}
4 của đối tượng
<fieldset>
  <legend>Choose your interestslegend>
  <div>
    <input type="checkbox" id="coding" name="interest" value="coding" checked />
    <label for="coding">Codinglabel>
  div>
  <div>
    <input type="checkbox" id="music" name="interest" value="music" />
    <label for="music">Musiclabel>
  div>
fieldset>
4 thông qua JavaScript (không thể đặt thuộc tính này bằng thuộc tính HTML)

inputInstance.indeterminate = true;

Một hộp kiểm ở trạng thái không xác định có một đường ngang trong hộp (trông hơi giống dấu gạch nối hoặc dấu trừ) thay vì dấu kiểm/đánh dấu trong hầu hết các trình duyệt

Không có nhiều trường hợp sử dụng cho tài sản này. Phổ biến nhất là khi có sẵn một hộp kiểm "sở hữu" một số tùy chọn phụ (cũng là hộp kiểm). Nếu tất cả các tùy chọn phụ được chọn, hộp kiểm sở hữu cũng được chọn và nếu tất cả chúng không được chọn, hộp kiểm sở hữu sẽ không được chọn. Nếu bất kỳ một hoặc nhiều tùy chọn phụ nào có trạng thái khác với các tùy chọn khác, thì hộp kiểm sở hữu ở trạng thái không xác định

Điều này có thể được nhìn thấy trong ví dụ dưới đây (nhờ CSS Tricks cho nguồn cảm hứng). Trong ví dụ này, chúng tôi theo dõi các thành phần mà chúng tôi đang thu thập cho một công thức. Khi bạn chọn hoặc bỏ chọn hộp kiểm của một thành phần, hàm JavaScript sẽ kiểm tra tổng số thành phần đã chọn

  • Nếu không có cái nào được chọn, hộp kiểm của tên công thức được đặt thành không được chọn
  • Nếu một hoặc hai được chọn, hộp kiểm của tên công thức được đặt thành
    const overall = document.querySelector('#enchantment');
    const ingredients = document.querySelectorAll('ul input');
    
    overall.addEventListener('click', (e) => {
      e.preventDefault();
    });
    
    for (const ingredient of ingredients) {
      ingredient.addEventListener('click', updateDisplay);
    }
    
    function updateDisplay() {
      let checkedCount = 0;
      for (const ingredient of ingredients) {
        if (ingredient.checked) {
          checkedCount++;
        }
      }
    
      if (checkedCount === 0) {
        overall.checked = false;
        overall.indeterminate = false;
      } else if (checkedCount === ingredients.length) {
        overall.checked = true;
        overall.indeterminate = false;
      } else {
        overall.checked = false;
        overall.indeterminate = true;
      }
    }
    
    4
  • Nếu cả ba đều được chọn, hộp kiểm của tên công thức được đặt thành
    <fieldset>
      <legend>Choose your interestslegend>
      <div>
        <input type="checkbox" id="coding" name="interest" value="coding" checked />
        <label for="coding">Codinglabel>
      div>
      <div>
        <input type="checkbox" id="music" name="interest" value="music" />
        <label for="music">Musiclabel>
      div>
    fieldset>
    
    3

Vì vậy, trong trường hợp này, trạng thái

const overall = document.querySelector('#enchantment');
const ingredients = document.querySelectorAll('ul input');

overall.addEventListener('click', (e) => {
  e.preventDefault();
});

for (const ingredient of ingredients) {
  ingredient.addEventListener('click', updateDisplay);
}

function updateDisplay() {
  let checkedCount = 0;
  for (const ingredient of ingredients) {
    if (ingredient.checked) {
      checkedCount++;
    }
  }

  if (checkedCount === 0) {
    overall.checked = false;
    overall.indeterminate = false;
  } else if (checkedCount === ingredients.length) {
    overall.checked = true;
    overall.indeterminate = false;
  } else {
    overall.checked = false;
    overall.indeterminate = true;
  }
}
4 được sử dụng để nói rằng việc thu thập nguyên liệu đã bắt đầu, nhưng công thức vẫn chưa hoàn thành

const overall = document.querySelector('#enchantment');
const ingredients = document.querySelectorAll('ul input');

overall.addEventListener('click', (e) => {
  e.preventDefault();
});

for (const ingredient of ingredients) {
  ingredient.addEventListener('click', updateDisplay);
}

function updateDisplay() {
  let checkedCount = 0;
  for (const ingredient of ingredients) {
    if (ingredient.checked) {
      checkedCount++;
    }
  }

  if (checkedCount === 0) {
    overall.checked = false;
    overall.indeterminate = false;
  } else if (checkedCount === ingredients.length) {
    overall.checked = true;
    overall.indeterminate = false;
  } else {
    overall.checked = false;
    overall.indeterminate = true;
  }
}

Ghi chú. Nếu bạn gửi biểu mẫu có hộp kiểm không xác định, điều tương tự sẽ xảy ra như thể hộp kiểm không được chọn — không có dữ liệu nào được gửi để đại diện cho hộp kiểm

Các hộp kiểm hỗ trợ xác thực (được cung cấp cho tất cả các ). Tuy nhiên, hầu hết các

const overall = document.querySelector('#enchantment');
const ingredients = document.querySelectorAll('ul input');

overall.addEventListener('click', (e) => {
  e.preventDefault();
});

for (const ingredient of ingredients) {
  ingredient.addEventListener('click', updateDisplay);
}

function updateDisplay() {
  let checkedCount = 0;
  for (const ingredient of ingredients) {
    if (ingredient.checked) {
      checkedCount++;
    }
  }

  if (checkedCount === 0) {
    overall.checked = false;
    overall.indeterminate = false;
  } else if (checkedCount === ingredients.length) {
    overall.checked = true;
    overall.indeterminate = false;
  } else {
    overall.checked = false;
    overall.indeterminate = true;
  }
}
9 sẽ luôn là
<form>
  <fieldset>
    <legend>Choose your interestslegend>
    <div>
      <input type="checkbox" id="coding" name="interest" value="coding" />
      <label for="coding">Codinglabel>
    div>
    <div>
      <input type="checkbox" id="music" name="interest" value="music" />
      <label for="music">Musiclabel>
    div>
    <div>
      <input type="checkbox" id="art" name="interest" value="art" />
      <label for="art">Artlabel>
    div>
    <div>
      <input type="checkbox" id="sports" name="interest" value="sports" />
      <label for="sports">Sportslabel>
    div>
    <div>
      <input type="checkbox" id="cooking" name="interest" value="cooking" />
      <label for="cooking">Cookinglabel>
    div>
    <div>
      <input type="checkbox" id="other" name="interest" value="other" />
      <label for="other">Otherlabel>
      <input type="text" id="otherValue" name="other" />
    div>
    <div>
      <button type="submit">Submit formbutton>
    div>
  fieldset>
form>
0. Nếu hộp kiểm có thuộc tính, nhưng không được chọn, thì
<form>
  <fieldset>
    <legend>Choose your interestslegend>
    <div>
      <input type="checkbox" id="coding" name="interest" value="coding" />
      <label for="coding">Codinglabel>
    div>
    <div>
      <input type="checkbox" id="music" name="interest" value="music" />
      <label for="music">Musiclabel>
    div>
    <div>
      <input type="checkbox" id="art" name="interest" value="art" />
      <label for="art">Artlabel>
    div>
    <div>
      <input type="checkbox" id="sports" name="interest" value="sports" />
      <label for="sports">Sportslabel>
    div>
    <div>
      <input type="checkbox" id="cooking" name="interest" value="cooking" />
      <label for="cooking">Cookinglabel>
    div>
    <div>
      <input type="checkbox" id="other" name="interest" value="other" />
      <label for="other">Otherlabel>
      <input type="text" id="otherValue" name="other" />
    div>
    <div>
      <button type="submit">Submit formbutton>
    div>
  fieldset>
form>
2 sẽ là
<form>
  <fieldset>
    <legend>Choose your interestslegend>
    <div>
      <input type="checkbox" id="coding" name="interest" value="coding" />
      <label for="coding">Codinglabel>
    div>
    <div>
      <input type="checkbox" id="music" name="interest" value="music" />
      <label for="music">Musiclabel>
    div>
    <div>
      <input type="checkbox" id="art" name="interest" value="art" />
      <label for="art">Artlabel>
    div>
    <div>
      <input type="checkbox" id="sports" name="interest" value="sports" />
      <label for="sports">Sportslabel>
    div>
    <div>
      <input type="checkbox" id="cooking" name="interest" value="cooking" />
      <label for="cooking">Cookinglabel>
    div>
    <div>
      <input type="checkbox" id="other" name="interest" value="other" />
      <label for="other">Otherlabel>
      <input type="text" id="otherValue" name="other" />
    div>
    <div>
      <button type="submit">Submit formbutton>
    div>
  fieldset>
form>
3

Ví dụ sau đây là phiên bản mở rộng của ví dụ "nhiều hộp kiểm" mà chúng ta đã thấy ở trên — ví dụ này có nhiều tùy chọn tiêu chuẩn hơn, cộng với hộp kiểm "khác" mà khi được chọn sẽ khiến một trường văn bản xuất hiện để nhập giá trị cho tùy chọn "khác". Điều này đạt được với một khối JavaScript đơn giản. Ví dụ này cũng bao gồm một số CSS để cải thiện kiểu dáng

Làm cách nào để gọi đầu vào trong CSS?

Nếu bạn chỉ muốn tạo kiểu cho một loại đầu vào cụ thể, bạn có thể sử dụng bộ chọn thuộc tính. .
input[type=text] - sẽ chỉ chọn các trường văn bản
input[type=password] - sẽ chỉ chọn các trường mật khẩu
đầu vào [loại = số] - sẽ chỉ chọn các trường số

Làm cách nào để thay đổi giá trị đầu vào trong CSS?

Không, CSS không thể thay đổi thuộc tính giá trị của đầu vào hoặc bất kỳ thuộc tính nào của bất kỳ phần tử nào.

Làm cách nào để tạo kiểu CSS cho tệp đầu vào?

Có ba bước để thực hiện việc này. .
Wrap the input file inside a label element.
Thay đổi hiển thị của thẻ đầu vào thành không. đầu vào{ hiển thị. không ai;
Tạo kiểu cho phần tử nhãn. Tại đây, bạn có thể thêm nhiều yếu tố hoặc biểu tượng. Đây là nơi ma thuật đến. nhãn{

Đầu vào trong CSS là gì?

Bộ chọn thuộc tính CSS chọn các loại đầu vào CSS cụ thể để tạo kiểu. input[type=text] - chọn các trường biểu mẫu chấp nhận văn bản . input[type=password] - chọn các trường biểu mẫu chấp nhận mật khẩu. đầu vào [loại = số] - chọn các trường biểu mẫu chấp nhận số. vân vân.