我正在开发一个项目,我需要复选框的背景为黄色,勾号的颜色为白色。
<div class="radio-btn">
<input type="checkbox" name="disclaimer" id="rad-1" required="" />
<label for="rad-1">Yes, please!</label>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的 HTML,它的样式写在下面
#rad-1 {
height: 20px;
width: 20px;
accent-color: yellow;
}
Run Code Online (Sandbox Code Playgroud)
背景变成黄色,但刻度线的颜色变成黑色我尝试过“颜色:白色;” 和“背景颜色:白色;” 但这些都不起作用,刻度线仍然是黑色的。
小智 2
我给你留了一个可能的例子:How TO - Custom Checkbox
首先我们隐藏浏览器的默认单选按钮
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)
现在我们创建一个自定义单选按钮
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
border-radius: 50%;
}
Run Code Online (Sandbox Code Playgroud)
完整示例
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
border-radius: 50%;
}
Run Code Online (Sandbox Code Playgroud)