您已经在使用Bootstrap的"自定义"表单控件(尽管稍微有些不正确 - Bootstrap 4自定义控件的标记与您的示例不同)。
这是Bootstrap 4自定义复选框的正确标记:
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck1">
<label class="custom-control-label" for="customCheck1">Check this custom checkbox</label>
</div>
自定义外观由custom-*
CSS类控制。如您所见,缺省颜色为Bootstrap的主要"蓝色"。如果要使其变成绿色,则需要覆盖或添加自己的自定义CSS类。以下是一个示例,使用了一个新类,以便如果您仍然想有时使用默认的蓝色,就可以这样做。
.custom-control-input-green:focus~.custom-control-label::before {
border-color: #28a745 !important;
box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25) !important;
}
.custom-control-input-green:checked~.custom-control-label::before {
border-color: #28a745 !important;
background-color: #28a745 !important;
}
.custom-control-input-green:focus:not(:checked)~.custom-control-label::before {
border-color: #5bd778 !important;
}
.custom-control-input-green:not(:disabled):active~.custom-control-label::before {
background-color: #d6f5dd !important;
border-color: #d6f5dd !important;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="custom-control custom-checkbox custom-checkbox-green">
<input type="checkbox" class="custom-control-input custom-control-input-green" id="customCheck1">
<label class="custom-control-label" for="customCheck1">Check this custom checkbox</label>
</div>
.custom-checkbox {
color: green;
accent-color: currentcolor;
}
checkbox_color
类。 - General Grievance