Created
January 18, 2012 00:44
-
-
Save Grawl/1630056 to your computer and use it in GitHub Desktop.
iOS-style checkbox
This file contains 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
/** | |
* iOS-style checkbox | |
*/ | |
h1{ | |
font-size:1.5em; | |
text-align:center; | |
margin-bottom:1em; | |
} | |
p { | |
margin:1em 0; | |
} | |
body { | |
font-family: "Helvetica Neue", Helvetica, "Lucida Grande", Verdana,Arial, sans-serif, Helvetica; | |
padding: 50px; | |
} | |
.checkbox { | |
margin:0 auto; | |
-webkit-user-select: none; | |
-khtml-user-select: none; | |
-moz-user-select: none; | |
-o-user-select: none; | |
user-select: none; | |
position:relative; | |
display: block; | |
width:94px; | |
} | |
.checkbox input[type=checkbox] { | |
display: none; | |
} | |
.checkbox input[type=checkbox] + label { | |
display: block; | |
cursor:pointer; | |
width: 94px; | |
overflow: hidden; | |
background:#fff; | |
-webkit-border-radius:3px; | |
-moz-border-radius:3px; | |
border-radius:3px; | |
background:-webkit-linear-gradient(left, #2d5ba8 50%, #999 50%) no-repeat -20px 0; | |
background:-moz-linear-gradient(left, #2d5ba8 50%, #999 50%) no-repeat-20px 0; | |
-webkit-transition: background-position 0.3s ease-in-out; | |
-moz-transition: background-position 0.3s ease-in-out; | |
} | |
.checkbox input[type=checkbox] + label span, | |
.checkbox input[type=checkbox] + label span:before, | |
.checkbox input[type=checkbox] + label span:after{ | |
text-align:center; | |
display:block; | |
width:54px; | |
height:27px; | |
line-height:27px; | |
position:absolute; | |
top:-1px; | |
font-weight:bold; | |
text-indent: 0; | |
-webkit-box-shadow:inset 1px 2px 2px 0 rgba(0,0,0,.2); | |
-moz-box-shadow:inset 1px 2px 2px 0 rgba(0,0,0,.2); | |
box-shadow:inset 1px 2px 2px 0 rgba(0,0,0,.2); | |
} | |
.checkbox input[type=checkbox] + label span{ | |
text-indent: -9999px; | |
top:0; | |
position:relative; | |
left:0; | |
width:37px; | |
-webkit-border-radius:3px; | |
-moz-border-radius:3px; | |
border-radius:3px; | |
background:-webkit-linear-gradient(#efefef 1px, #cecece 1px, #fbfbfb); | |
background:-moz-linear-gradient(#efefef 1px, #cecece 1px, #fbfbfb); | |
-webkit-transition: left 0.3s ease-in-out; | |
-moz-transition: left 0.3s ease-in-out; | |
border:solid 1px; | |
border-color: #919191 #9f9f9f #999999 #90aacf; | |
-webkit-box-shadow:none; | |
-moz-box-shadow:none; | |
box-shadow:none; | |
} | |
.checkbox input[type=checkbox] + label span:before{ | |
color:#eee; | |
text-shadow:0 1px rgba(255,255,255,.1), 0 -1px rgba(0,0,0,.3); | |
content:"ON"; | |
background:-webkit-linear-gradient(#285ab1, #7cadf2); | |
background:-moz-linear-gradient(#285ab1, #7cadf2); | |
border-top:solid 1px #133676; | |
border-bottom:solid 1px #6587b7; | |
border-radius:1px 0 0 1px; | |
left:-55px; | |
} | |
.checkbox input[type=checkbox] + label span:after{ | |
color:#888; | |
content:"OFF"; | |
left:auto; | |
right:-55px; | |
background:-webkit-linear-gradient(#ddd, #eee); | |
background:-moz-linear-gradient(#ddd, #eee); | |
border-top:solid 1px #7d7d7d; | |
border-bottom:solid 1px #c0c0c0; | |
} | |
.checkbox input[type=checkbox] + label:active span{ | |
left:5px; | |
} | |
.checkbox input[type=checkbox]:checked + label:active span{ | |
left:50px; | |
} | |
.checkbox input[type=checkbox]:checked + label span{ | |
left:55px; | |
} | |
.checkbox input[type=checkbox]:checked + label{ | |
background-position:20px; | |
} | |
.checkbox:before, | |
.checkbox:after{ | |
content: " "; | |
display:block; | |
position:absolute; | |
top:0; | |
left:93px; | |
width:1px; | |
height:27px; | |
border:solid #fff; | |
border-width:1px 0; | |
z-index:20; | |
background:#999; | |
} | |
.checkbox:before{ | |
left:0; | |
} |
This file contains 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="checkbox"> | |
<input id="check" checked type="checkbox" value="1" /> | |
<label for="check"><span>Check-me</span></label> | |
</div> |
This file contains 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
{"view":"split-vertical","prefixfree":"1","page":"css"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment