Created
September 20, 2019 17:27
-
-
Save benhorst/3cfc4fb791824e371897feb45fefcc9d to your computer and use it in GitHub Desktop.
Pure CSS Switches
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
<style> | |
.switch { | |
line-height: 1.5; | |
font-weight: normal; | |
font-family: Roboto,Helvetica,Arial,sans-serif; | |
-webkit-box-direction: normal; | |
list-style: none; | |
list-style-type: none; | |
font-size: .8rem; | |
color: #9e9e9e; | |
box-sizing: inherit; | |
-webkit-tap-highlight-color: transparent; | |
user-select: none; | |
} | |
.switch > label { | |
line-height: 1.5; | |
font-weight: normal; | |
font-family: Roboto,Helvetica,Arial,sans-serif; | |
-webkit-box-direction: normal; | |
list-style: none; | |
list-style-type: none; | |
box-sizing: inherit; | |
font-size: .8rem; | |
color: #9e9e9e; | |
-webkit-tap-highlight-color: transparent; | |
user-select: none; | |
cursor: pointer; | |
} | |
.switch label input[type=checkbox] { | |
opacity: 0; | |
width: 0; | |
height: 0; | |
}.switch label input[type=checkbox]:checked+.lever { | |
background-color: #84c7c1; | |
} | |
.switch label .lever { | |
content: ""; | |
display: inline-block; | |
position: relative; | |
width: 36px; | |
height: 14px; | |
background-color: rgba(0,0,0,0.38); | |
border-radius: 15px; | |
margin-right: 10px; | |
-webkit-transition: background 0.3s ease; | |
transition: background 0.3s ease; | |
vertical-align: middle; | |
margin: 0 16px; | |
} | |
.switch label .lever:before, .switch label .lever:after { | |
content: ""; | |
position: absolute; | |
display: inline-block; | |
width: 20px; | |
height: 20px; | |
border-radius: 50%; | |
left: 0; | |
top: -3px; | |
-webkit-transition: left 0.3s ease, background .3s ease, -webkit-box-shadow 0.1s ease, -webkit-transform .1s ease; | |
transition: left 0.3s ease, background .3s ease, -webkit-box-shadow 0.1s ease, -webkit-transform .1s ease; | |
transition: left 0.3s ease, background .3s ease, box-shadow 0.1s ease, transform .1s ease; | |
transition: left 0.3s ease, background .3s ease, box-shadow 0.1s ease, transform .1s ease, -webkit-box-shadow 0.1s ease, -webkit-transform .1s ease; | |
} | |
.switch label input[type=checkbox]:checked+.lever:after { | |
background-color: #26a69a; | |
} | |
.switch label input[type=checkbox]:checked+.lever:before, .switch label input[type=checkbox]:checked+.lever:after { | |
left: 18px; | |
} | |
.switch label .lever:after { | |
background-color: #F1F1F1; | |
-webkit-box-shadow: 0px 3px 1px -2px rgba(0,0,0,0.2), 0px 2px 2px 0px rgba(0,0,0,0.14), 0px 1px 5px 0px rgba(0,0,0,0.12); | |
box-shadow: 0px 3px 1px -2px rgba(0,0,0,0.2), 0px 2px 2px 0px rgba(0,0,0,0.14), 0px 1px 5px 0px rgba(0,0,0,0.12); | |
} | |
.switch label input[type=checkbox]:checked+.lever:before, .switch label input[type=checkbox]:checked+.lever:after { | |
left: 18px; | |
} | |
.switch label .lever:before { | |
background-color: rgba(38,166,154,0.15); | |
} | |
</style> | |
<div class="switch"> | |
<label>Off<input type="checkbox" name="hints" checked=""><span class="lever"></span>On</label> | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://jsfiddle.net/798sebug/