Skip to content

Instantly share code, notes, and snippets.

@silicakes
Created June 20, 2017 08:29
Show Gist options
  • Save silicakes/3b950ad552eae3b9bbe0b5d957a8d0f8 to your computer and use it in GitHub Desktop.
Save silicakes/3b950ad552eae3b9bbe0b5d957a8d0f8 to your computer and use it in GitHub Desktop.
Pure CSS switch
<div class="switch-wrapper">
<input type="checkbox" class="checkbox" id="checkbox"/>
<label for="checkbox" class="switch" data-off="off" data-on="on"/>
</div>
.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