自定义单选按钮边框颜色

时间:2019-01-09 04:27:14

标签: html reactjs css3 css-selectors

赋予单选按钮不同颜色以及边框颜色的最佳方法?单选按钮为true时。

我的代码可以正常工作,但广播为true时边框颜色除外。
      为:after和:before添加了CSS,请检查以下代码。

CSS3:

.planItem [type="radio"]:checked,
.planItem [type="radio"]:not(:checked) {
    position: absolute;
    left: -9999px;
}
.planItem [type="radio"]:checked + label,
.planItem [type="radio"]:not(:checked) + label
{
    position: relative;
    padding-left: 38px;
    cursor: pointer;
    line-height: 20px;
    display: inline-block;
    color: #666;
}
.planItem [type="radio"]:checked + label:before,
.planItem [type="radio"]:not(:checked) + label:before {
    content: '';
    position: absolute;
    left: 15px;
    top: 10px;
    width: 15px;
    height: 15px;
    border: 1px solid #ddd;
    border-radius: 100%;
    background: #fff;
}
.planItem [type="radio"]:checked + label:after,
.planItem [type="radio"]:not(:checked) + label:after {
    content: '';
    width: 9px;
    height: 9px;
    background: #0086D6;
    position: absolute;
    top: 13px;
    left: 18px;
    border-radius: 100%;
    -webkit-transition: all 0.2s ease;
    transition: all 0.2s ease;
}
.planItem [type="radio"]:not(:checked) + label:after {
    opacity: 0;
    -webkit-transform: scale(0);
    transform: scale(0);
}
.planItem [type="radio"]:checked + label:after {
    opacity: 1;
    -webkit-transform: scale(1);
    transform: scale(1);
}
.planItem [type="radio"]:checked + label{
    background: linear-gradient(315deg, #F9EEFE 0%, #E8F5FF 100%);
}
.planItem [type="radio"] + label {
    width: 100%;
    padding-top: 10px;
    padding-left: 35px;
    /*border-bottom: 1px solid #E3E9EC;*/
    height: 40px;
}

JSX:

<div className = "planItem">            
{
    this.state.planItems && this.state.planItems.map(function (smsType, i){
        return <div className={smsType.id} key={i}><input type="radio" id={smsType.id} name="radio-group-menu" onClick={() => this.planhandleClick(smsType.id)}/> 
            <label className="mb-0" htmlFor={smsType.id}>{smsType.name}</label>  
        </div>
    }, this)
}
</div>

如何设置边框颜色,如下图所示?
enter image description here

2 个答案:

答案 0 :(得分:1)

选中单选时添加border: 1px solid #0086D6;

.planItem [type="radio"]:checked + label:before {
    border: 1px solid #0086D6;
}

希望这会有所帮助。

答案 1 :(得分:1)

请检查sample code。在为整个容器label:hover添加的悬停中,当悬停时选中或未选中收音机时,将应用以下样式.planItem [type="radio"]:hover + label:before{ border-color: #04acec; },最后,如果选中了收音机,我们将为:before {{1}添加边框}