Hiển thị các bài đăng có nhãn Input Checkbox Css. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Input Checkbox Css. Hiển thị tất cả bài đăng

Thứ Ba, 23 tháng 12, 2025

Checkbox Limit - chọn giới hạn trong checkbox

 


<!DOCTYPE html>

<html lang="vi">

<head>

  <meta charset="UTF-8">

  <title>Checkbox Dropdown - Show Value</title>

  <style>

    body {

      font-family: Arial, sans-serif;

      background: #f5f5f5;

      padding: 40px;

    }

    .container {

      width: 420px;

      margin: auto;

      background: #fff;

      padding: 20px;

      border-radius: 8px;

      box-shadow: 0 2px 8px rgba(0,0,0,.1);

    }

    .dropdown { position: relative; }

    .dropdown-btn {

      width: 100%;

      padding: 10px;

      border: 1px solid #ccc;

      border-radius: 6px;

      background: #fff;

      cursor: pointer;

      text-align: left;

    }

    .dropdown-menu {

      position: absolute;

      top: 45px;

      left: 0;

      width: 100%;

      background: #fff;

      border-radius: 8px;

      border: 1px solid #ddd;

      box-shadow: 0 4px 12px rgba(0,0,0,.15);

      padding: 12px;

      display: none;

      z-index: 10;

    }

    .dropdown-menu label {

      display: flex;

      align-items: center;

      margin-bottom: 8px;

      cursor: pointer;

    }

    .dropdown-menu input { margin-right: 8px; }

    .disabled { color: #aaa; cursor: not-allowed; }

    .selected-info {

      font-size: 13px;

      color: #666;

      margin-bottom: 8px;

    }

    .tags { margin-top: 12px; }

    .tag {

      display: inline-block;

      background: #ffe7d9;

      color: #ff6a00;

      padding: 4px 8px;

      border-radius: 6px;

      font-size: 13px;

      margin-right: 6px;

      margin-bottom: 6px;

    }

  </style>

</head>

<body>


<div class="container">

  <h3>Business Type</h3>


  <form method="POST" action="submit.php">


    <!-- INPUT GỬI BACKEND -->

    <input type="hidden" name="searchname" id="searchname">


    <div class="dropdown">

      <button type="button" class="dropdown-btn" id="dropdownBtn">

        Chọn loại hình kinh doanh

      </button>


      <div class="dropdown-menu" id="dropdownMenu">

        <div class="selected-info">

          Selected: <span id="count">0</span>/3

        </div>


        <label><input type="checkbox" value="Import and Export">Import and Export</label>

        <label><input type="checkbox" value="Retail & Agency">Retail & Agency</label>

        <label><input type="checkbox" value="Manufacturer">Manufacturer</label>

        <label><input type="checkbox" value="Wholesale">Wholesale</label>

        <label><input type="checkbox" value="Service Provider">Service Provider</label>

      </div>

    </div>


    <div class="tags" id="tags"></div>


    <button style="margin-top:15px;width:100%">Submit</button>

  </form>

</div>


<script>

  const dropdownBtn = document.getElementById("dropdownBtn");

  const dropdownMenu = document.getElementById("dropdownMenu");

  const checkboxes = dropdownMenu.querySelectorAll("input[type=checkbox]");

  const countEl = document.getElementById("count");

  const tagsEl = document.getElementById("tags");

  const hiddenInput = document.getElementById("searchname");

  const MAX = 3;

  const placeholder = "Chọn loại hình kinh doanh";


  dropdownBtn.onclick = () => {

    dropdownMenu.style.display =

      dropdownMenu.style.display === "block" ? "none" : "block";

  };


  document.addEventListener("click", e => {

    if (!e.target.closest(".dropdown")) {

      dropdownMenu.style.display = "none";

    }

  });


  checkboxes.forEach(cb => {

    cb.addEventListener("change", () => {

      const checked = [...checkboxes].filter(c => c.checked);

      if (checked.length > MAX) {

        cb.checked = false;

        return;

      }

      updateUI();

    });

  });


  function updateUI() {

    const checked = [...checkboxes].filter(c => c.checked);

    countEl.textContent = checked.length;


    // Disable khi đủ 3

    checkboxes.forEach(cb => {

      const label = cb.parentElement;

      if (!cb.checked && checked.length === MAX) {

        cb.disabled = true;

        label.classList.add("disabled");

      } else {

        cb.disabled = false;

        label.classList.remove("disabled");

      }

    });


    const values = checked.map(c => c.value);


    // 👉 HIỆN TRONG BUTTON

    dropdownBtn.textContent =

      values.length ? values.join(", ") : placeholder;


    // 👉 GỬI FORM

    hiddenInput.value = values.join(",");


    // // Tags

    // tagsEl.innerHTML = values

    //   .map(v => `<span class="tag">${v}</span>`)

    //   .join("");

  }

</script>


</body>

</html>


Thứ Ba, 15 tháng 2, 2022

Input Checkbox Css

 




****HTML:

<h1>Custom Checkboxes</h1>

<label class="container">One

  <input type="checkbox" checked="checked">

  <span class="checkmark"></span>

</label>

<label class="container">Two

  <input type="checkbox">

  <span class="checkmark"></span>

</label>

<label class="container">Three

  <input type="checkbox">

  <span class="checkmark"></span>

</label>

<label class="container">Four

  <input type="checkbox">

  <span class="checkmark"></span>

</label>

 ****CSS:

.container {

  display: block;

  position: relative;

  padding-left: 35px;

  margin-bottom: 12px;

  cursor: pointer;

  font-size: 22px;

  -webkit-user-select: none;

  -moz-user-select: none;

  -ms-user-select: none;

  user-select: none;

}


/* Hide the browser's default checkbox */

.container input {

  position: absolute;

  opacity: 0;

  cursor: pointer;

  height: 0;

  width: 0;

  border-radius:100%;

}


/* Create a custom checkbox */

.checkmark {

  position: absolute;

  top: 0;

  left: 0;

  height: 25px;

  width: 25px;

  background-color: #eee;

  border-radius:100%;

}


/* On mouse-over, add a grey background color */

.container:hover input ~ .checkmark {

  background-color: #ccc;

}


/* When the checkbox is checked, add a blue background */

.container input:checked ~ .checkmark {

  background-color: #2196F3;

}


/* Create the checkmark/indicator (hidden when not checked) */

.checkmark:after {

  content: "";

  position: absolute;

  display: none;

}


/* Show the checkmark when checked */

.container input:checked ~ .checkmark:after {

  display: block;

}


/* Style the checkmark/indicator */

.container .checkmark:after {

  left: 9px;

  top: 5px;

  width: 5px;

  height: 10px;

  border: solid white;

  border-width: 0 3px 3px 0;

  -webkit-transform: rotate(45deg);

  -ms-transform: rotate(45deg);

  transform: rotate(45deg);

}