Skip to content

Instantly share code, notes, and snippets.

@wunnle
Created April 18, 2018 14:33
Show Gist options
  • Save wunnle/5bb8da427c0f2a294e614d82185073dc to your computer and use it in GitHub Desktop.
Save wunnle/5bb8da427c0f2a294e614d82185073dc to your computer and use it in GitHub Desktop.
Toggle button
<label for="checkbox">
<input type="checkbox" class="swp-toggle-checkbox" id="checkbox">
<div class="swp-toggle">
<div class="swp-toggle-pill"></div>
</div>
</label>
.swp-toggle-checkbox {
opacity: 0;
width: 0;
height: 0; // still accessible
}
.swp-toggle-checkbox + .swp-toggle {
display: block;
width: 30px;
height: 16px;
background: #B7BABF;
border-radius: 26px;
opacity: 1;
padding: 2px;
box-sizing: border-box;
margin: auto;
display: flex;
transition: background 0.5s ease;
.swp-toggle-pill {
display: block;
width: 12px;
height: 12px;
background: white;
border-radius: 10px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
margin-left: 0;
transition: margin 0.08s cubic-bezier(0.77, 0.49, 1, 1);
}
}
.swp-toggle-checkbox:checked + .swp-toggle {
background: #4079F5;
transition: background 0.5s ease;
.swp-toggle-pill {
margin-left: calc(100% - 12px);
}
}
// unrelated stuff
body {
display: flex;
height: 400px;
}
label {
background: rgba(222, 222, 222, 0.2);
width: 200px;
height: 200px;
display: flex;
align-items: center;
justify-self: center;
justify-items: center;
text-align: center;
margin: auto;
}
.swp-toggle-checkbox + .swp-toggle {
transform: scale(2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment