Created
October 12, 2012 06:29
-
-
Save dhornbein/3877622 to your computer and use it in GitHub Desktop.
Simple checkbox label turns into rocker switch. Added a little light so you know when it's on
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 action="" class="m-rocker"> | |
<input id="switch" type="checkbox"><label for="switch">Switch</label> | |
<input id="switch2" type="checkbox"><label for="switch2">Switch</label> | |
<input id="switch3" type="checkbox"><label for="switch3">Switch</label> | |
</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
body { background-color:#444; box-shadow:inset 0px 0px 80px #000; text-align:center; width:100%; height:500px; padding-top:20px; margin:0;} | |
.m-rocker { | |
font-size:180% | |
} | |
.m-rocker:not(:checked) > input { | |
position: absolute; | |
top: -9999px; | |
clip: rect(0,0,0,0); | |
} | |
.m-rocker:not(:checked) > label:before { | |
content:''; | |
display:block; | |
background-color:green; | |
width:40%; | |
height:2px; | |
margin:0 5%; | |
position:absolute; | |
top:0; | |
left:0; | |
} | |
.m-rocker:not(:checked) > label { | |
background-color:#222; | |
border-color:#445 #334 #223; | |
border-width:.25em; | |
border-style:solid; | |
border-radius:.2em; | |
cursor: pointer; | |
display: inline-block; | |
padding: 0 .5em; | |
margin-right:1em; | |
position:relative; | |
text-indent: -5000px; | |
width:1.5em; | |
height:3.5em; | |
} | |
/* on */ | |
.m-rocker:not(:checked) > input:checked + label:before { | |
background-color:lime; | |
box-shadow:0 0 4px #eeffee, 0 0 6px #DDFFDD, 0 0 12px #DDFFDD; | |
top:20%; | |
} | |
.m-rocker:not(:checked) > input:checked + label { | |
background: #eeeeee; /* Old browsers */ | |
background: -moz-linear-gradient(top, #eeeeee 0%, #efefef 12%, #999999 15%, #111111 50%, #444444 95%, #111111 100%); /* FF3.6+ */ | |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(12%,#efefef), color-stop(15%,#999999), color-stop(50%,#111111), color-stop(95%,#444444), color-stop(100%,#111111)); /* Chrome,Safari4+ */ | |
background: -webkit-linear-gradient(top, #eeeeee 0%,#efefef 12%,#999999 15%,#111111 50%,#444444 95%,#111111 100%); /* Chrome10+,Safari5.1+ */ | |
background: -o-linear-gradient(top, #eeeeee 0%,#efefef 12%,#999999 15%,#111111 50%,#444444 95%,#111111 100%); /* Opera 11.10+ */ | |
background: -ms-linear-gradient(top, #eeeeee 0%,#efefef 12%,#999999 15%,#111111 50%,#444444 95%,#111111 100%); /* IE10+ */ | |
background: linear-gradient(to bottom, #eeeeee 0%,#efefef 12%,#999999 15%,#111111 50%,#444444 95%,#111111 100%); /* W3C */ | |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#111111',GradientType=0 ); /* IE6-9 */ | |
} | |
/* on - hover */ | |
.m-rocker:not(:checked) > input:checked + label:active:before { | |
top:17%; | |
} | |
.m-rocker:not(:checked) > input:checked + label:active { | |
background: #eeeeee; /* Old browsers */ | |
background: -moz-linear-gradient(top, #eeeeee 0%, #efefef 8%, #999999 11%, #111111 50%, #444444 92%, #111111 95%, #111111 100%); /* FF3.6+ */ | |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(8%,#efefef), color-stop(11%,#999999), color-stop(50%,#111111), color-stop(92%,#444444), color-stop(95%,#111111), color-stop(100%,#111111)); /* Chrome,Safari4+ */ | |
background: -webkit-linear-gradient(top, #eeeeee 0%,#efefef 8%,#999999 11%,#111111 50%,#444444 92%,#111111 95%,#111111 100%); /* Chrome10+,Safari5.1+ */ | |
background: -o-linear-gradient(top, #eeeeee 0%,#efefef 8%,#999999 11%,#111111 50%,#444444 92%,#111111 95%,#111111 100%); /* Opera 11.10+ */ | |
background: -ms-linear-gradient(top, #eeeeee 0%,#efefef 8%,#999999 11%,#111111 50%,#444444 92%,#111111 95%,#111111 100%); /* IE10+ */ | |
background: linear-gradient(to bottom, #eeeeee 0%,#efefef 8%,#999999 11%,#111111 50%,#444444 92%,#111111 95%,#111111 100%); /* W3C */ | |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#111111',GradientType=0 ); /* IE6-9 */ | |
} | |
/* off */ | |
.m-rocker input:not(:checked) + label:before { | |
background-color:darkgreen; | |
top:4%; | |
} | |
.m-rocker input:not(:checked) + label { | |
background: #eeeeee; /* Old browsers */ | |
background: -moz-linear-gradient(top, #eeeeee 0%, #999999 2%, #111111 50%, #444444 78%, #565656 85%, #111111 87%, #000000 100%); /* FF3.6+ */ | |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(2%,#999999), color-stop(50%,#111111), color-stop(78%,#444444), color-stop(85%,#565656), color-stop(87%,#111111), color-stop(100%,#000000)); /* Chrome,Safari4+ */ | |
background: -webkit-linear-gradient(top, #eeeeee 0%,#999999 2%,#111111 50%,#444444 78%,#565656 85%,#111111 87%,#000000 100%); /* Chrome10+,Safari5.1+ */ | |
background: -o-linear-gradient(top, #eeeeee 0%,#999999 2%,#111111 50%,#444444 78%,#565656 85%,#111111 87%,#000000 100%); /* Opera 11.10+ */ | |
background: -ms-linear-gradient(top, #eeeeee 0%,#999999 2%,#111111 50%,#444444 78%,#565656 85%,#111111 87%,#000000 100%); /* IE10+ */ | |
background: linear-gradient(to bottom, #eeeeee 0%,#999999 2%,#111111 50%,#444444 78%,#565656 85%,#111111 87%,#000000 100%); /* W3C */ | |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#000000',GradientType=0 ); /* IE6-9 */ | |
} | |
/* off - down */ | |
.m-rocker input:not(:checked) + label:active:before { | |
margin-top:3%; | |
} | |
.m-rocker input:not(:checked) + label:active { | |
background: #eeeeee; /* Old browsers */ | |
background: -moz-linear-gradient(top, #eeeeee 0%, #ffffff 3%, #999999 5%, #111111 50%, #444444 89%, #111111 92%, #000000 100%); /* FF3.6+ */ | |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(3%,#ffffff), color-stop(5%,#999999), color-stop(50%,#111111), color-stop(89%,#444444), color-stop(92%,#111111), color-stop(100%,#000000)); /* Chrome,Safari4+ */ | |
background: -webkit-linear-gradient(top, #eeeeee 0%,#ffffff 3%,#999999 5%,#111111 50%,#444444 89%,#111111 92%,#000000 100%); /* Chrome10+,Safari5.1+ */ | |
background: -o-linear-gradient(top, #eeeeee 0%,#ffffff 3%,#999999 5%,#111111 50%,#444444 89%,#111111 92%,#000000 100%); /* Opera 11.10+ */ | |
background: -ms-linear-gradient(top, #eeeeee 0%,#ffffff 3%,#999999 5%,#111111 50%,#444444 89%,#111111 92%,#000000 100%); /* IE10+ */ | |
background: linear-gradient(to bottom, #eeeeee 0%,#ffffff 3%,#999999 5%,#111111 50%,#444444 89%,#111111 92%,#000000 100%); /* W3C */ | |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#000000',GradientType=0 ); /* IE6-9 */ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment