我正在做一个项目,我需要复选框的背景是黄色,勾号的 colored颜色 是白色.

        <div class="radio-btn">
             <input type="checkbox" name="disclaimer" id="rad-1" required="" />
             <label for="rad-1">Yes, please!</label>
        </div>

这是我的HTML,它的样式写在下面

#rad-1 {
        height: 20px;
        width: 20px;
        accent-color: yellow;
    }

背景变为黄色,但蜱虫的 colored颜色 变为黑色

here's how it looks enter image description here

推荐答案

我给你一个可能的例子:How TO - Custom Checkbox

首先,我们隐藏浏览器的默认单选按钮

.container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

现在我们创建了一个自定义单选按钮

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 25px;
  width: 25px;
  background-color: #eee;
  border-radius: 50%;
}

FULL EXAMPLE

body {
  background-color: grey;
}


/* The container */

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


/* Hide the browser's default radio button */

.container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}


/* Create a custom radio button */

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 25px;
  width: 25px;
  background-color: #eee;
  border-radius: 50%;
}


/* On mouse-over, add a grey background color */

.container:hover input~.checkmark {
  background-color: #ccc;
}


/* When the radio button is checked, add a blue background */

.container input:checked~.checkmark {
  background-color: yellow;
}


/* Create the indicator (the dot/circle - hidden when not checked) */

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}


/* Show the indicator (dot/circle) when checked */

.container input:checked~.checkmark:after {
  display: block;
}


/* Style the indicator (dot/circle) */

.container .checkmark:after {
  top: 9px;
  left: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: white;
}
<h1>Custom Radio Buttons</h1>
<label class="container">One
  <input type="radio" checked="checked" name="radio">
  <span class="checkmark"></span>
</label>
<label class="container">Two
  <input type="radio" name="radio">
  <span class="checkmark"></span>
</label>
<label class="container">Three
  <input type="radio" name="radio">
  <span class="checkmark"></span>
</label>
<label class="container">Four
  <input type="radio" name="radio">
  <span class="checkmark"></span>
</label>

Html相关问答推荐

如何找到FontAwese图标的Unicode值?

如何才能只给没有孟加拉语Kar符号的字母上色?

首字下沉非字母字符

如何防止可见的滑动抽屉,同时转移HTML方向?

如何最大限度地减少Cookie同意代码对性能的影响?

创建带有弯曲边框的水平时间线

如何翻转卡片图像的背面

在每个列宽由带有固定值的minmax()函数定义的网格中,CSS如何为列分配空间?

如何将文本环绕心形(而不仅仅是圆形)?

减小HTML负载中base64字符串的大小

配置了 HTML 视口的 Google Apps 脚本移动网络应用程序无法正确显示

:invalid Select 器的惰性判断

网格中的图像zoom 不正确

如何并排放置部分?