Skip to content

Instantly share code, notes, and snippets.

@RickardAhlstedt
Created May 16, 2019 09:33
Show Gist options
  • Save RickardAhlstedt/19e6ff7dcc184ee392df6687f4ec3793 to your computer and use it in GitHub Desktop.
Save RickardAhlstedt/19e6ff7dcc184ee392df6687f4ec3793 to your computer and use it in GitHub Desktop.
iOS 7 Toggle
<div class="toggle">
<input type="checkbox" class="check">
<b class="b switch"></b>
<b class="b track"></b>
</div>

iOS 7 Toggle

CSS/HTML only recreation of the iOS 7 toggle buttons. I love the little bounce that the slide has.

A Pen by Daniel Eden on CodePen.

License.

* {
margin: 0;
padding: 0;
position: relative;
box-sizing: border-box;
}
html, body {
height: 100%;
}
.b {
display: block;
}
.toggle {
position: absolute;
top: 50%;
left: 50%;
width: 60px;
height: 40px;
border-radius: 100px;
background-color: #ddd;
margin: -20px -40px;
overflow: hidden;
box-shadow: inset 0 0 2px 1px rgba(0,0,0,.05);
}
.check {
position: absolute;
display: block;
cursor: pointer;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
z-index: 6;
}
.check:checked ~ .track {
box-shadow: inset 0 0 0 20px #4bd863;
}
.check:checked ~ .switch {
right: 2px;
left: 22px;
transition: .35s cubic-bezier(0.785, 0.135, 0.150, 0.860);
transition-property: left, right;
transition-delay: .05s, 0s;
}
.switch {
position: absolute;
left: 2px;
top: 2px;
bottom: 2px;
right: 22px;
background-color: #fff;
border-radius: 36px;
z-index: 1;
transition: .35s cubic-bezier(0.785, 0.135, 0.150, 0.860);
transition-property: left, right;
transition-delay: 0s, .05s;
box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.track {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
transition: .35s cubic-bezier(0.785, 0.135, 0.150, 0.860);
box-shadow: inset 0 0 0 2px rgba(0,0,0,.05);
border-radius: 40px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment