我已创建CSS复选框。它基于我削减的CodePen脚本,但是我找不到如何修改“required”复选框。我能做的最好的就是改变“悬停”上的方块阴影的颜色,但是我尽可能的接近。如何修改CSS复选框标签以包含“必需”功能
以下是我有:
.checkbox1 {
width: 25px;
margin: 20px 100px;
position: relative;
}
.checkbox1 label {
cursor: pointer;
position: absolute;
width: 16px;
height: 16px;
top: 2px;
left: 3px;
background: linear-gradient(#ffffff, #dddddd 80%);
border: 0.5px solid #7d878d;
border-radius: 4px;
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.2);
}
.checkbox1 label:after {
opacity: 0.0;
content: '';
position: absolute;
width: 14px;
height: 6px;
background: transparent;
top: 1px;
left: 2px;
border: 3px solid #ff6600;
border-top: none;
border-right: none;
transform: rotate(-50deg);
}
.checkbox1 label::after {
opacity: 0.0;
}
.checkbox1 input[type=checkbox]:checked+label:after {
opacity: 5;
}
.checkbox2 {
width: 25px;
margin: 20px 100px;
position: relative;
}
.checkbox2 label {
cursor: pointer;
position: absolute;
width: 16px;
height: 16px;
top: 2px;
left: 3px;
background: linear-gradient(#ffffff, #dddddd 80%);
border: 0.5px solid #7d878d;
border-radius: 4px;
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.2);
}
.checkbox2 label:after {
opacity: 0.0;
content: '';
position: absolute;
width: 14px;
height: 6px;
background: transparent;
top: 1px;
left: 2px;
border: 3px solid #ff6600;
border-top: none;
border-right: none;
transform: rotate(-50deg);
}
.checkbox2 label::after {
opacity: 0.0;
}
.checkbox2 label:hover {
box-shadow: 0px 0px 4px 0px #ff0000;
opacity: 5;
}
.checkbox2 input[type=checkbox]:checked+label:after {
opacity: 5;
}
<div class="checkbox1">
<input type="checkbox" value="1" id="input1" name="" />
<label for="input1"></label>
</div>
<div class="checkbox2">
<input type="checkbox" value="2" id="input2" name="" required="" />
<label for="input2"></label>
</div>
所要求的,你的意思是你需要一些动作停止,除非该复选框被选中? – gkubed
谢谢你的回应。当你取消勾选复选框时,我希望CSS复选框的行为与默认的html“required”复选框一样。那就是将箱形阴影改为红色以表明这是一个必需的动作 - 箱子必须被检查才能继续。一旦箱子重新检查,箱形阴影的红色被取消。 – Robert