Created
June 20, 2017 08:29
-
-
Save silicakes/3b950ad552eae3b9bbe0b5d957a8d0f8 to your computer and use it in GitHub Desktop.
Pure CSS switch
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 class="switch-wrapper"> | |
<input type="checkbox" class="checkbox" id="checkbox"/> | |
<label for="checkbox" class="switch" data-off="off" data-on="on"/> | |
</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
.switch-wrapper { | |
position: relative; | |
.checkbox { | |
display: none; | |
} | |
.checkbox:checked + .switch { | |
background: lighten(#369, 20%); | |
&:after { | |
transform: translateX(40px); | |
} | |
&:before { | |
content: attr(data-on); | |
} | |
} | |
.switch { | |
display: block; | |
width: 70px; | |
height: 30px; | |
background: #ccc; | |
border-radius: 20px; | |
overflow: hidden; | |
box-shadow: inset 0 2px 3px 0 rgba(#000, .2); | |
&:before { | |
text-transform: uppercase; | |
content: attr(data-off); | |
position: absolute; | |
left: 75px; | |
top: 9px; | |
} | |
&:after { | |
display: block; | |
content: ""; | |
width: 30px; | |
height: 30px; | |
border-radius: 50%; | |
background: #fff; | |
transition: transform .1s ease-in-out; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment