gpt4 book ai didi

html - 更改复选框的颜色

转载 作者:行者123 更新时间:2023-12-02 01:41:02 27 4
gpt4 key购买 nike

我正在做一个元素,我需要复选框的背景为黄色,勾号的颜色为白色。

        <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;
}

背景变成黄色但是tick的颜色变成黑色我试过“颜色:白色;”和“背景颜色:白色;”但这些都不起作用,刻度线保持黑色。

这是它的样子 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%;
}

完整示例

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 - 更改复选框的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71588463/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com