Created
April 18, 2021 17:21
-
-
Save SamantazFox/c87a7c4930f8ae59050a84a8b4e044c3 to your computer and use it in GitHub Desktop.
Tiny CSS-only on/off button
This file contains 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
<div> | |
<!-- This can be placed in any structure element, like <div>, <td>, etc... --> | |
<input id="my_checkbox1" name="input1" type="checkbox" hidden=""> | |
<label for="my_checkbox1"><span></span></label> | |
</div> |
This file contains 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
/* On-Off Indicator */ | |
label { | |
--color-enabled: #18984a; | |
--color-disabled: #7d7d7d; | |
width: 2.8em; height: 1.4em; | |
margin: 0; padding: 0; | |
display: inline-block; | |
background-color: var(--color-disabled); | |
border-top-left-radius: 25% 50%; | |
border-bottom-left-radius: 25% 50%; | |
border-top-right-radius: 25% 50%; | |
border-bottom-right-radius: 25% 50%; | |
} | |
label > span { | |
display: block; | |
background-color: #fff; | |
width: 1em; | |
height: 1em; | |
border-radius: 50%; | |
margin: 0.2em; | |
padding: 0; | |
float: left; | |
} | |
/* Modfify nearby indicator when checkbox is checked */ | |
input[type="checkbox"]:checked ~ label { background-color: var(--color-enabled); } | |
input[type="checkbox"]:checked ~ label > span { float: right; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment