我正在尝试根据Bootstrap 4自定义表单制作纯css自定义复选框。复选框在除Windows11上的IE11之外的所有浏览器上都能正常工作(IE11 + Windows 7正常工作)。奇怪的是:当我使用鼠标光标鼠标选择所有文本或我调整浏览器窗口大小时,它开始工作 - 滴答声神奇地出现。
这就是我设法做的事情:
.custom-checkbox {
position: relative;
display: block;
min-height: 30px;
padding-left: 40px;
padding-top: 4px;
}
.custom-checkbox .custom-checkbox-input {
position: absolute;
z-index: -1;
opacity: 0;
box-sizing: border-box;
padding: 0;
margin: 0;
overflow: visible;
font-family: inherit;
font-size: inherit;
line-height: inherit;
}
.custom-checkbox .custom-checkbox-input:disabled~.custom-checkbox-label {
color: #6c757d;
}
.custom-checkbox .custom-checkbox-input:disabled~.custom-checkbox-label::before {
box-sizing: border-box;
background-color: #e9ecef;
border-color: #c9c9c9;
}
.custom-checkbox .custom-checkbox-input::checked~.custom-checkbox-label::before {
box-sizing: border-box;
color: #fff;
background-color: #fff;
}
.custom-checkbox .custom-checkbox-input::checked~.custom-checkbox-label::after {
background-color: red;
}
.custom-checkbox .custom-checkbox-input:checked~.custom-checkbox-label::after {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%230065F9' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3E%3C/svg%3E");
}
.custom-checkbox .custom-checkbox-input:disabled:checked~.custom-control-label::after {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%23a4c8fc' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3E%3C/svg%3E");
}
.custom-checkbox .custom-checkbox-label {
margin-bottom: 0;
display: inline-block;
}
.custom-checkbox .custom-checkbox-label::before {
box-sizing: border-box;
position: absolute;
top: 4px;
left: 0;
display: block;
width: 23px;
height: 23px;
pointer-events: none;
content: "";
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-color: #fff;
border: 2px solid #0065F9;
}
.custom-checkbox .custom-checkbox-label::after {
box-sizing: border-box;
position: absolute;
top: 4px;
left: 0;
display: block;
width: 23px;
height: 23px;
content: "";
background-repeat: no-repeat;
background-position: center center;
background-size: 65% 65%;
}

<div class="custom-checkbox">
<input type="checkbox" class="custom-checkbox-input" id="customCheck1">
<label class="custom-checkbox-label" for="customCheck1">
Check this custom checkbox
</label>
</div>
&#13;