I created some custom checkboxes which work great:
https://codepen.io/anon/pen/jwxXar
I tried to do the same with radio buttons. But if one radio button is active and I click another one, the unchecking does not work:
➤ https://codepen.io/anon/pen/YQLdxd
Custom Radio Buttons CSS Code
.radio {
position: relative;
margin-bottom: 10px;
}
.radio input[type="radio"] {
cursor: pointer;
height: 100%;
left: 0;
margin: 0;
opacity: 0;
position: absolute;
top: 0;
width: 100%;
z-index: 1;
}
.radio label {margin-left: 32px;}
.radio label:before,
.radio label:after {
content: "";
display: block;
position: absolute;
}
.radio label:before {
background: #fff;
border: 1px solid #ccc;
border-radius: 50%;
height: 20px;
left: 0;
top: 4px;
width: 20px;
}
.radio label:after {
background: red;
border-radius: 50%;
height: 12px;
left: 5px;
opacity: 0;
pointer-events: none;
top: 9px;
width: 12px;
}
.radio input:checked ~ label:after {opacity: 1;}
input[type="radio"]:checked + label:before {
border: 1px solid red;
box-shadow: inset 0 0 0 1px #fff, inset 0 0 0 0 #fff, inset 0 0 0 16px #fff;
color: #fff;
}
Custom Radio Buttons HTMLCode
<div class="radio">
<input value="" type="radio">
<label>Radio Button 1</label>
</div>
<div class="radio">
<input value="" type="radio">
<label>Radio Button 2</label>
</div>
<div class="radio">
<input value="" type="radio">
<label>Radio Button 3</label>
</div>
<div class="radio">
<input value="" type="radio">
<label>Radio Button 4</label>
</div>
Does anyone of the CSS Super Heros have an idea, why the radio buttons are not working?