Created
June 1, 2013 19:32
-
-
Save stuartlangridge/5691475 to your computer and use it in GitHub Desktop.
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
<!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> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment