Last active
August 10, 2023 23:17
-
-
Save martinwolf/6434799 to your computer and use it in GitHub Desktop.
SCSS: Pure CSS radio and checkbox inputs
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
.input-helper { | |
position: relative; | |
display: inline-block; | |
&:before { | |
content: ''; | |
display: block; | |
position: absolute; | |
} | |
} | |
.input-helper--radio { | |
padding-left: 18px; | |
&:before { | |
top: 1px; | |
left: 0; | |
width: 10px; | |
height: 10px; | |
border-radius: 50%; | |
border: 1px solid #222; | |
} | |
} | |
.input-helper--checkbox { | |
padding-left: 20px; | |
&:before { | |
top: 0; | |
left: 0; | |
width: 13px; | |
height: 13px; | |
border: 1px solid #222; | |
} | |
} | |
input[type="radio"] { | |
display: none; | |
&:checked + label:before { | |
background: #222; | |
} | |
} | |
input[type="checkbox"] { | |
display: none; | |
&:checked + label:before { | |
background: #222; | |
} | |
} |
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> | |
<input id="radio-input-1" type="radio" value="myValue 1" name="radio-group" checked> | |
<label for="radio-input-1" class="input-helper input-helper--radio">myValue 1</label> | |
<input id="radio-input-2" type="radio" value="myValue 2" name="radio-group"> | |
<label for="radio-input-2" class="input-helper input-helper--radio">myValue 2</label> | |
<input id="checkbox-input-1" type="checkbox" value="myValue 1" checked> | |
<label for="checkbox-input-1" class="input-helper input-helper--checkbox">myValue 1</label> | |
<input id="checkbox-input-2" type="checkbox" value="myValue 2"> | |
<label for="checkbox-input-2" class="input-helper input-helper--checkbox">myValue 2</label> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment