【发布时间】:2021-03-24 22:20:21
【问题描述】:
I have a problem with Bootstrap 4 radio and checkboxes custom styles.
I want to recreate:
我设法更改了背景,但是当按下单选框或复选框时,我无法更改样式。 我对可以粘贴的数据 SVG 没有经验,我在一些论坛上看到您也可以这样做。
另外,我尝试将自己的图像作为 SVG 文件添加到我的 css background-image: url() 但无法识别。
下面的 HTML 和 CSS 代码
.custom-control-label::before {
background-color: #f1f2ec;
border: 2px solid #678000;
height: 21px;
width: 21px;
border-radius: 22px;
box-sizing: border-box;
}
/* This is the checked state */
.custom-radio .custom-control-input:checked~.custom-control-label::before,
.custom-radio .custom-control-input:checked~.custom-control-label::after {
/* background-color: #678000; */
/* border: 2px solid #678000; */
/* this bg image SVG is just a white circle, you can replace it with any valid SVG code */
background-image: url("/images/radio-pressed.svg");
border-radius: 50%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Radio -->
<div class="col-6 pt-5">
<form>
<div class="custom-control custom-radio">
<input type="radio" class="custom-control-input" id="radioBtn2">
<label for="radioBtn2" class="custom-control-label"></label>
</div>
</form>
</div>
<!-- Checkbox -->
<div class="col-6 pt-5 pb-5">
<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>
</div>
我也在网上看到了一些演示,但它们并没有真正帮助我。 任何帮助将不胜感激!
【问题讨论】:
-
click here这就是你想要的??
标签: html css bootstrap-4