我正在尝试设置不带标签的Bootstrap 4复选框的样式:
<div class="form-check">
<input class="form-check-input position-static" type="checkbox" id="blankCheckbox" value="option1">
</div>
我的尝试和错误样式:
.form-check {
.form-check-input {
color: #2c2b2c;
font-size: 12px;
line-height: 2.7;
padding-left:15px;
text-transform: uppercase;
background-color: red;
}
.form-check-input::after,
.form-check-input::before {
height: 25px;
width: 25px;
}
.form-check-input::before {
background-color: #fff;
border: 1px solid #2c2b2c;
}
}
}
我可以设置标签版本的样式,但此版本失败。
更新:如@ mebin-joe所述,这是一个已知问题:https://github.com/twbs/bootstrap/issues/26221 我最终使用了自定义的Bootstrap复选框元素并设置了样式:
.custom-checkbox .custom-control-input:checked~.custom-control-label::before
{
background-color: #caca4c;
}
.custom-control-input:checked~.custom-control-label::before {
color: #fff;
background-color: #caca4c;
}
答案 0 :(得分:0)
似乎在Bootstrap 4.5.0上可以正常工作
<div class=" custom-control custom-radio">
<label id="N1" class="sr-only">XXX</label>
<input class="custom-control-input" aria-labelledby="N1" type="radio" value="XX">
<span class="custom-control-label"></span>
</div>
或仅根据需要
<div class=" custom-control custom-radio">
<label for="N1" class="sr-only">XXX</label>
<input id="N1" class="custom-control-input" type="radio" value="XX">
<span class="custom-control-label"></span>
</div>
答案 1 :(得分:0)
请使用以下代码,它将起作用:
<div class="custom-control custom-radio" role="group">
<input
type="radio"
name="quest-27"
id="quest-27-10"
class="custom-control-input"
value="1">
<label class="custom-control-label">
<span class="sr-only">Never</span>
</label>