Skip to content

Instantly share code, notes, and snippets.

@Manoz
Created February 13, 2014 09:42
Show Gist options
  • Save Manoz/8972374 to your computer and use it in GitHub Desktop.
Save Manoz/8972374 to your computer and use it in GitHub Desktop.
Toggle button in pure CSS
/* Toggle button in pure CSS
* Wanted to make a cool button but, finally, I think I'm going in the wrong way.
* Original button : http://dribbble.com/shots/408190-Quick-Setting-Toggles
*/
body {
text-align: center;
background-color: #dcdfe5;
}
p {
text-shadow:
0 1px 0 rgba(255,255,255,.7) ,
0 -1px 0 rgba(0,0,0,.5);
font-size: 28px;
color: #777;
}
.btn-bg {
position: relative;
z-index: 1;
width: 160px;
height: 80px;
margin: 0 auto;
border-top: 1px solid #a5a7ac;
border-bottom: 1px solid #fff;
border-radius: 60px;
background: #ccc;
background: #bdbfc1;
background: linear-gradient(
to bottom,
#bbbdbf 15%,
#f8fafd 100%);
}
.btn-in {
position: relative;
top: 11px;
left: 15px;
width: 130px;
height: 55px;
border: 1px solid #A2A2A2;
border-radius: 60px;
background: #c8c8c8;
background: linear-gradient(
25deg,#fff 0,
#c8c8c8 100%);
box-shadow:
inset -3px 0px 8px rgba(126,126,126,0.6),
inset 2px 1px 1px rgba(255,255,255,.5);
transition: all .2s linear;
}
.btn-in:before,
.btn-in:after {
content: '';
z-index: -1;
position: absolute;
bottom: 27px;
left: 16px;
width: 70%;
height: 82%;
box-shadow: 0 20px 18px rgba(0,0,0,0.3);
border-radius: 60px;
transform: skew(-26deg)rotate(-12deg);
transition: all .2s linear;
}
input:checked ~ .btn-in:before,
input:checked ~ .btn-in:after {
content: '';
z-index: -1;
position: absolute;
bottom: 27px;
left: 28px;
width: 70%;
height: 82%;
box-shadow: 0 20px 18px rgba(0,0,0,0.3);
border-radius: 60px;
transform: skew(26deg)rotate(12deg);
}
input:checked ~ .btn-in {
background: #fff;
background: linear-gradient(
166deg,
#c8c8c8 0,
#fff 100%);
box-shadow:
inset 3px 0px 8px rgba(0,0,0,0.2),
inset -2px 1px 1px rgba(255,255,255,.5);
}
input {
display: block;
z-index: 10;
position: absolute;
top: 12px;
left: 16px;
width: 130px;
height: 55px;
margin: 0;
padding: 0;
opacity: 0;
cursor: pointer;
}
span {
position: absolute;
top: 17px;
transition: all .2s linear;
}
.on {
left: 25px;
text-shadow:
0 -1px 0 rgba(0,0,0,.3),
0 1px 0 rgba(255,255,255,.5);
color: #aaa;
}
.off {
right: 25px;
text-shadow:
0 -1px 0 rgba(0,0,0,.3),
0 1px 0 rgba(255,255,255,.5);
color: #e27618;
}
input:checked ~ .btn-in .on {
color: #e27618;
transition: all .2s linear;
}
input:checked ~ .btn-in .off {
color: #aaa;
transition: all .2s linear;
}
<p>Music</p>
<div class="btn-bg">
<input type="checkbox" checked>
<div class="btn-in">
<span class="on">on</span>
<span class="off">off</span>
</div>
</div>
// alert('Hello world!');
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment