A Pen by Daniel Hannih on CodePen.
-
-
Save Pandahisham/1fa09a47c2661433c05ea34292d3dfa6 to your computer and use it in GitHub Desktop.
iOS-like Toggle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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! */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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