Skip to content

Instantly share code, notes, and snippets.

@CodeMyUI
Last active July 29, 2020 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeMyUI/a2cf1b7eaee6e2c37fd14bc96b99b36d to your computer and use it in GitHub Desktop.
Save CodeMyUI/a2cf1b7eaee6e2c37fd14bc96b99b36d to your computer and use it in GitHub Desktop.
Switchers (Checkboxes)
<span class="switcher switcher-1">
<input type="checkbox" id="switcher-1">
<label for="switcher-1"></label>
</span>
<span class="switcher switcher-2">
<input type="checkbox" id="switcher-2">
<label for="switcher-2"></label>
</span>
/*
https://dribbble.com/shots/4898152-Switcher-PRD
But the colors are the correct way around on this pen, as I think a checkbox should say what it is - not what it will be when you click it
*/
<script src="https://codepen.io/z-/pen/a8e37caf2a04602ea5815e5acedab458"></script>
$black:#1E1E1E;
$grey:#CCCCCC;
$white:#FFFFFF;
body {
display:flex;
flex-direction:column;
align-items:center;
justify-content:center;
height:100vh;
background-color:$grey;
span.switcher {
position: relative;
width:200px;
height:50px;
border-radius:25px;
margin:20px 0;
input {
appearance: none;
position: relative;
width:200px;
height:50px;
border-radius:25px;
background-color:$black;
outline:none;
font-family: 'Oswald', sans-serif;
&:before, &:after {
z-index:2;
position: absolute;
top:50%;
transform:translateY(-50%);
color:$white;
}
&:before {
content: 'ON';
left:20px;
}
&:after {
content: 'OFF';
right:20px;
}
}
label {
z-index:1;
position: absolute;
top:10px;
bottom:10px;
border-radius:20px;
}
&.switcher-1 {
input {
transition:.25s -.1s;
&:checked {
background-color:$white;
&:before {
color:$white;
transition: color .5s .2s;
}
&:after {
color:$grey;
transition: color .5s;
}
&+label {
left:10px;
right:100px;
background:$black;
transition: left .5s, right .4s .2s;
}
}
&:not(:checked) {
background:$black;
transition: background .5s -.1s;
&:before {
color:$grey;
transition: color .5s;
}
&:after {
color:$black;
transition: color .5s .2s;
}
&+label {
left:100px;
right:10px;
background:$white;
transition: left .4s .2s, right .5s, background .35s -.1s;
}
}
}
}
&.switcher-2 {
overflow:hidden;
input {
transition:background-color 0s .5s;
&:before {
color:$black;
}
&:after {
color:$white;
}
&:checked {
background-color:$white;
&+label {
background:$white;
animation: turn-on .5s ease-out;
@keyframes turn-on {
0% {
left:100%;
}
100% {
left:0%;
}
}
}
}
&:not(:checked) {
background:$black;
&+label {
background:$black;
animation: turn-off .5s ease-out;
@keyframes turn-off {
0% {
right:100%;
}
100% {
right:0%;
}
}
}
}
}
label {
top:0px;
width:200px;
height:50px;
border-radius:25px;
}
}
}
}
<link href="https://fonts.googleapis.com/css?family=Oswald:700" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment