html - CSS 自定义复选框

标签 html css checkbox

我有一个包含 30 个复选框的页面。那些是为了预订座位。 现在我试着给它们设计风格。

.seatlayout{
  border: 1px solid;
  display: table;
  width: 30%;
  padding: 6% 2% 0% 2%;
  border-radius: 5%;
}
.seat{
  position: relative;
  width: 22%;
  margin-bottom: 10%;
  float: left;
  text-align: center;
  border: 1px solid #ccc;
}
[class*='seatcont'],
.seatdis{
  position: relative;
  width: 100%;
  height: 100%;
}

[class^="seatcon"] label,
.seatdis label{
  background-color: #f1f2ed;
  cursor: pointer;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

[class^="seatcon"] input[type="checkbox"] ,
.seatdis input[type="checkbox"] {
  z-index:10

}

[class^="seatcon"] input[type="checkbox"]:checked + label
{
  background-color: #66bb6a;
}

.seatdis input[type="checkbox"]:checked + label{
  background-color: grey;
  pointer-events: none
}

[class^="seatcon"] input[type="checkbox"]:checked +  
label:after {
  opacity: 1;
}
<div class="seatlayout">
 <div class="seat">
    <div class="seatcont1">
       <input type="checkbox id="checkbox">
       <label for="checkbox" id="lab1">
    </div>
 </div>
 <div class="seat">
    <div class="seatcont2">
       <input type="checkbox id="checkbox">
       <label for="checkbox" id="lab2">
    </div>
 </div>
 <div class="seat">
    <div class="seatcont3">
       <input type="checkbox id="checkbox">
       <label for="checkbox" id="lab3">
    </div>
 </div>
</div>

Problem No matter on which seat i click on, it always checkes the first one. I tried several approaches adding unique classes and id's while working with wildcards. Any help would be highly apprieciated!

最佳答案

您在所有复选框上都设置了相同的 ID。你需要给他们一个不同的ID。 此外,您在类型后的所有复选框上都缺少结束引号。

<input type="checkbox" id="checkbox">
<label for="checkbox" id="lab1">

....

<input type="checkbox" id="checkbox2">
<label for="checkbox2" id="lab1">

关于html - CSS 自定义复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54540063/

相关文章:

android - 如何为所有元素设置相同的选择器?

javascript - 复选框过滤 HTML 表 jQuery

html - chrome css 动画抖动

javascript - 在输入中输入数据,然后只显示在页面其他地方输入的文本

css - 为什么我的代码没有在网络浏览器中生成? XML、DTD、CSS

css - HTML 页面第一次和第二次加载不同(Google Chrome)

android - Android Listview 中的编辑模式

javascript - 如何将json数据动态插入到html元素中

css - 在没有父容器的情况下对齐两个 <div>

html - SCSS 图像路径不起作用