Skip to content

Instantly share code, notes, and snippets.

@CodeMyUI
Created October 24, 2016 13:29
Show Gist options
  • Save CodeMyUI/3a121942fd8ff79b96544eb03b759aa1 to your computer and use it in GitHub Desktop.
Save CodeMyUI/3a121942fd8ff79b96544eb03b759aa1 to your computer and use it in GitHub Desktop.
iOS-like Toggle
<div class="the-amazing-toggle">
<!-- The Tease -->
<h1>The amazing Toggle.</h1>
<h2>Satisfy your togglediction.</h2>
<!-- The Toggle -->
<input type="checkbox" id="toggly">
<label for="toggly"><i></i></label>
<!-- The Addiction -->
<p>Toggle it. Come on. I know you want it.<br>
<a target="_blank" href="https://twitter.com/danielhannih">by Daniel Hannih</a></p>
</div>
/* Checkbox body */
label {
display: block;
width: 54px;
height: 32px;
margin: 0px auto;
border-radius: 100px;
transition: all 0.2s ease-in-out;
-webkit-transition: all 0.2s ease-in-out;
background-color: #E6E9EC;
}
input {
display: none;
}
/* The toggle */
i {
height: 28px;
width: 28px;
background: #ffffff;
display: inline-block;
border-radius: 100px;
margin-top: 2px;
margin-left: 2px;
transition: all 0.2s ease-in-out;
-webkit-transition: all 0.2s ease-in-out;
pointer-events: none;
box-shadow: 0px 0px 0px 0px rgba(0, 0, 0, 0);
}
label:hover>i {
box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.20);
transform: scale(1.01);
}
input:checked+label>i {
margin-left: 24px;
}
label:active {
background-color: #A6B9CB;
}
label:active>i {
width: 34px;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.20);
}
input:checked+label:active>i {
margin-left: 18px;
}
input:checked+label {
background-color: #008FFF;
}
/* nice to have stuff */
body {
font-family: 'Source Sans Pro', arial, sans-serif;
color: #303336;
font-weight: 300;
}
h1 {
font-size: 50px;
text-align: center;
margin-bottom: 20px;
}
h2 {
font-size: 28px;
text-align: center;
margin-bottom: 50px;
}
p {
text-align: center;
font-size: 14px;
letter-spacing: 0.02em;
margin-top: 50px;
color: #B6B9BC;
}
a {
line-height: 30px;
color: #008FFF;
text-decoration: none;
transition: all 0.2s ease-in-out;
-webkit-transition: all 0.2s ease-in-out;
}
a:hover {
color: #FF0062;
}
.the-amazing-toggle {
margin-top: 25vh;
}
/* Hope you enjoy the toggle as much as I do! Follow me @danielhannih on Twitter! */
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment