Pavan
Pavan

Reputation: 129

Custom radio button border color

Best way to give a different color of my radio button as well the border color? When it radio button is true.

My code works fine,except border color when radio is true.
CSS added for :after and :before, Kindly check below code.

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>

How can i set border color, like picture shown below?
enter image description here

Upvotes: 3

Views: 2228

Answers (2)

Balaji731
Balaji731

Reputation: 1129

Kindly check the sample code. In that added hover for overall container label:hover, when hover if the radio is checked or unchecked the below style is applied.planItem [type="radio"]:hover + label:before{ border-color: #04acec; } and finally if the radio check we add a border for the :before.planItem [type="radio"]:checked + label::before { border-color: #04acec; }

Upvotes: 1

Hai Pham
Hai Pham

Reputation: 2225

Add border: 1px solid #0086D6; when radio is checked:

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

Hope this will help.

Upvotes: 1

Related Questions