Touch toggle
Input checkbox styling, touch style. No JS, only CSS, and no extra markup. Design inspired by http://dribbble.com/shots/580766-expswitch?list=searches&tag=switch
by laustdeleuran
March 08, 2013
HTML
<div class="content">
<input type="checkbox" name="switch" id="switch" />
<label for="switch">
Switch me!
</label>
</div>
CSS
html {
margin: 0;
padding: 2em;
font-family: "Open Sans", Arial, sans-serif;
color: #333;
font-size: 16px;
text-align: center;
background:#111;
}
body {
margin: 0;
padding: 0;
}
.content {
display: inline-block;
margin: 0 auto;
padding: 1em;
position: relative;
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #eeeeee), color-stop(100%, #bbbbbb));
background: -webkit-linear-gradient(#eeeeee, #bbbbbb);
background: -moz-linear-gradient(#eeeeee, #bbbbbb);
background: -o-linear-gradient(#eeeeee, #bbbbbb);
background: linear-gradient(#eeeeee, #bbbbbb);
border-radius: 10px;
box-shadow: 0 3px 5px rgba(0, 0, 0, 0.5);
}
input {
position: absolute;
visibility: hidden;
left: -100px;
}
label {
height: 1.5em;
position: relative;
line-height: 1.5em;
cursor: pointer;
-webkit-transition: all 0.5s cubic-bezier(0.77, 0, 0.175, 1);
-moz-transition: all 0.5s cubic-bezier(0.77, 0, 0.175, 1);
-o-transition: all 0.5s cubic-bezier(0.77, 0, 0.175, 1);
transition: all 0.5s cubic-bezier(0.77, 0, 0.175, 1);
}
label:before,
label:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
content: "\2000";
display: block;
}
label:before {
float: left;
width: 100px;
margin-right: 10px;
height: 25px;
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ef8e03), color-stop(100%, #df2a00)), #df2a00;
background: -webkit-linear-gradient(#ef8e03, #df2a00), #df2a00;
background: -moz-linear-gradient(#ef8e03, #df2a00), #df2a00;
background: -o-linear-gradient(#ef8e03, #df2a00), #df2a00;
background: linear-gradient(#ef8e03, #df2a00), #df2a00;
border-radius: 1em;
box-shadow: inset 0 0 0.5em rgba(0, 0, 0, 0.5), 0 -1px 0 1px rgba(0, 0, 0, 0.2), 0 1px 0 1px rgba(255, 255, 255, 0.5), 0 -1px 0 2px rgba(0, 0, 0, 0.2), 0 1px 0 2px rgba(255, 255, 255, 0.5);
}
label:after {
width: 50px;
height: 27px;
position: absolute;
top: -2px;
...