Bootstrap 复选框CSS无法更改复选框的背景色[重复]

csbfibhn  于 2023-08-01  发布在  Bootstrap
关注(0)|答案(4)|浏览(138)

此问题已在此处有答案

How to style a checkbox using CSS(43答案)
6天前关闭
我想将我的复选框更改为此颜色#FA9E57。我使用的是bootstrap v4.6。
这是我的checkbox代码:

input[type=checkbox]{
    width: 20px;
    height: 20px;
    background-color: #FA9E57;
}

input[type=checkbox]:checked{
    background-color: #FA9E57;
}

个字符

wn9m85ua

wn9m85ua1#

您可以使用accent-color CSS属性来更改复选框和单选按钮的背景颜色。

input[type=checkbox] {
  accent-color: red;
}

字符串
这将仅在选中/选择输入后显示颜色。

toe95027

toe950272#

试试这个
css和html的复选框

.container {
  display: block;
  position: relative;
  padding-left: 35px;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 22px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Hide the browser's default checkbox */
.container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

/* Create a custom checkbox */
.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 25px;
  width: 25px;
  background-color: #FA9E57;
}

/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
  background-color: #FA9E57;
}

/* When the checkbox is checked, add a blue background */
.container input:checked ~ .checkmark {
  background-color: #FA9E57;
}

/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

/* Show the checkmark when checked */
.container input:checked ~ .checkmark:after {
  display: block;
}

/* Style the checkmark/indicator */
.container .checkmark:after {
  left: 9px;
  top: 5px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 3px 3px 0;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
}

个字符

dl5txlt9

dl5txlt93#

不支持修改复选框颜色

相反,创建具有背景自定义背景颜色的伪元素,如下所示:

.form-check {
  position: relative;
}

input[type=checkbox] {
  width: 20px;
  height: 20px;
}

input[type=checkbox]:checked+label::before {
  content: "";
  display: block;
  position: absolute;
  text-align: center;
  height: 20px;
  width: 20px;
  left: 0;
  top: 5px;
  background-color: #FA9E57;
  font-family: "Montserrat";
  border-radius: 2px;
  border: 1px solid rgb(150 150 150 / 30%);
}

input[type=checkbox]:checked+label::after {
  content: url('data:image/svg+xml; utf8, <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="white" viewBox="0 0 24 24"><path d="M20.285 2l-11.285 11.567-5.286-5.011-3.714 3.716 9 8.728 15-15.285z"/></svg>');
  display: block;
  position: absolute;
  left: 3px;
  top: 3px;
}

个字符

  • :before元素用于设置背景颜色,:after元素包含svg用于勾选。*
up9lanfz

up9lanfz4#

请添加一些CSS代码。

input[type=checkbox], input[type=checkbox]:checked {
  -moz-appearance:none;
  -webkit-appearance:none;
  -o-appearance:none;
}

字符串
为了让你的代码工作,你需要上面的代码。

相关问题