public

  • Download Gist
Pure CSS toggle switch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Pure CSS toggle switch</title>
<style>
body {
font-size: 2em;
}
input { position: absolute; opacity: 0 }
input + label::after {
content: ".";
border: 2px solid black;
border-radius: 600px;
margin-left: 12px;
width: 150px;
display: inline-block;
text-indent: -1000em;
}
 
input + label + input + label::after {
width: 0;
border-width: 0
}
 
input + label + input + label {
padding-right: 0;
padding-left: 150px;
margin-left: -150px;
background-image: -webkit-radial-gradient(circle, transparent 0%, transparent 50%, black 50%, black 54%, transparent 59%, transparent 100%);
background-position: 0px -1px;
background-size: 40px 105%;
background-repeat: no-repeat;
}
 
input:checked + label {
color: red
}
 
input + label + input:checked + label {
padding-left: 40px;
margin-left: -40px;
}
 
input + label + input + label {
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
</style>
</head>
<body>
<input type="radio" id="i1" name="i" checked><label for="i1">Coffee</label><input type="radio" id="i2" name="i"><label for="i2">Tea</label>
 
<p>Discursive blog post at http://kryogenix.org/days/2013/06/01/pure-css-toggle-switch-with-two-labels</p>
 
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.