Created
March 15, 2019 05:14
-
-
Save asifvora/6bef36a77f61a523ec90565fb1c8cfec to your computer and use it in GitHub Desktop.
Creates a toggle switch with CSS only.
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
<style> | |
.switch { | |
position: relative; | |
display: inline-block; | |
width: 40px; | |
height: 20px; | |
background-color: rgba(0, 0, 0, 0.25); | |
border-radius: 20px; | |
transition: all 0.3s; | |
} | |
.switch::after { | |
content: ''; | |
position: absolute; | |
width: 18px; | |
height: 18px; | |
border-radius: 18px; | |
background-color: white; | |
top: 1px; | |
left: 1px; | |
transition: all 0.3s; | |
} | |
input[type='checkbox']:checked + .switch::after { | |
transform: translateX(20px); | |
} | |
input[type='checkbox']:checked + .switch { | |
background-color: #7983ff; | |
} | |
.offscreen { | |
position: absolute; | |
left: -9999px; | |
} | |
</style> | |
<input type="checkbox" id="toggle" class="offscreen" /> <label for="toggle" class="switch"></label> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment