gpt4 book ai didi

css - 选择时更改单选按钮的边框颜色

转载 作者:技术小花猫 更新时间:2023-10-29 11:46:12 25 4
gpt4 key购买 nike

当我选择它时,我希望有一个绿色边框包围的绿色单选按钮。
这是我的:

input[type='radio'] {
-webkit-appearance: none;
width: 10px;
height: 10px;
border-radius: 50%;
outline: none;
box-shadow: 0 0 0 2px gray;
}

input[type='radio']:before {
content: '';
display: block;
width: 60%;
height: 60%;
margin: 20% auto;
border-radius: 50%;
}

input[type='radio']:checked:before {
background: green;
}

.role {
margin-right: 80px;
margin-left: 20px;
font-weight: normal;
}

.checkbox label {
margin-bottom: 20px !important;
}

.roles {
margin-bottom: 40px;
}

和模板:

<div class="roles">
<input type="radio" name="role" value="ONE" id="one">
<label class="role" for="one">ONE</label>
<input type="radio" name="role" value="TWO" id="two">
<label class="role" for="two">TWO</label>
</div>

这是一个 Jsfiddle:Demo

就像您看到的那样,border-color 永远不会变为绿色...我尝试添加 border-color 属性无济于事...我该怎么做?< br/>

谢谢!

最佳答案

你需要检查你的CSS。您得到的边框是由 box-shadow 而不是边框​​创建的:

这是一个正在工作的 fiddle 。玩得开心

input[type='radio'] {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
outline: none;
border: 3px solid gray;
}

input[type='radio']:before {
content: '';
display: block;
width: 60%;
height: 60%;
margin: 20% auto;
border-radius: 50%;
}

input[type="radio"]:checked:before {
background: green;

}

input[type="radio"]:checked {
border-color:green;
}

.role {
margin-right: 80px;
margin-left: 20px;
font-weight: normal;
}

.checkbox label {
margin-bottom: 20px !important;
}

.roles {
margin-bottom: 40px;
}
<div class="roles">
<input type="radio" name="role" value="ONE" id="one">
<label class="role" for="one">ONE</label>
<input type="radio" name="role" value="TWO" id="two">
<label class="role" for="two">TWO</label>
</div>

关于css - 选择时更改单选按钮的边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43589287/

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