Created
September 14, 2018 08:33
-
-
Save solid-pixel/564603083ec234f8999679a22a8326c2 to your computer and use it in GitHub Desktop.
Custom radio button CSS only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="#"> | |
<p> | |
<input type="radio" id="test1" name="radio-group" checked> | |
<label for="test1">Apple</label> | |
</p> | |
<p> | |
<input type="radio" id="test2" name="radio-group"> | |
<label for="test2">Peach</label> | |
</p> | |
<p> | |
<input type="radio" id="test3" name="radio-group"> | |
<label for="test3">Orange</label> | |
</p> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[type="radio"]:checked, | |
[type="radio"]:not(:checked) { | |
position: absolute; | |
left: -9999px; | |
} | |
[type="radio"]:checked + label, | |
[type="radio"]:not(:checked) + label | |
{ | |
position: relative; | |
padding-left: 28px; | |
cursor: pointer; | |
line-height: 20px; | |
display: inline-block; | |
color: #666; | |
} | |
[type="radio"]:checked + label:before, | |
[type="radio"]:not(:checked) + label:before { | |
content: ''; | |
position: absolute; | |
left: 0; | |
top: 0; | |
width: 18px; | |
height: 18px; | |
border: 1px solid #ddd; | |
border-radius: 100%; | |
background: #fff; | |
} | |
[type="radio"]:checked + label:after, | |
[type="radio"]:not(:checked) + label:after { | |
content: ''; | |
width: 12px; | |
height: 12px; | |
background: #F87DA9; | |
position: absolute; | |
top: 4px; | |
left: 4px; | |
border-radius: 100%; | |
-webkit-transition: all 0.2s ease; | |
transition: all 0.2s ease; | |
} | |
[type="radio"]:not(:checked) + label:after { | |
opacity: 0; | |
-webkit-transform: scale(0); | |
transform: scale(0); | |
} | |
[type="radio"]:checked + label:after { | |
opacity: 1; | |
-webkit-transform: scale(1); | |
transform: scale(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment