Bootstrap button toggle switch
Created
March 28, 2015 19:57
-
-
Save f8lrebel/a589dcdaa1390cd3e205 to your computer and use it in GitHub Desktop.
Button switch
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
- var brands = ['primary','success','info','warning','danger'] | |
- each brand in brands | |
.btn-switch(class="btn-switch-#{brand}") | |
input(type='checkbox', id='input-btn-switch-#{brand}') | |
label.btn.btn-round(for='input-btn-switch-#{brand}', class="btn-#{brand}") | |
em.glyphicon.glyphicon-ok | |
strong CLICK ME |
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
@brand-primary: #428bca; | |
@brand-success: #26ae90; | |
@brand-info: #5bc0de; | |
@brand-warning: #f0ad4e; | |
@brand-danger: #d9534f; | |
body { | |
text-align: center; | |
margin: 50px; | |
} | |
.btn-round { | |
border-radius: 40px; | |
} | |
.btn-switch { | |
position: relative; | |
display: inline-block; | |
cursor: pointer; | |
/* @only demo */ | |
margin: 10px; | |
> input[type="checkbox"] { | |
position: absolute; | |
opacity: 0; | |
visibility: hidden; | |
cursor:pointer; | |
left:-100%; | |
top:-100%; | |
+ .btn { | |
background-color: transparent; | |
border-color: @brand-danger; | |
color: @brand-danger; | |
> em { | |
display: inline-block; | |
border: 1px solid @brand-danger; | |
border-radius: 50%; | |
padding: 2px; | |
margin: 0 4px 0 0; | |
top: 0; | |
font-size: 10px; | |
text-align: center; | |
&:before { | |
opacity: 0; | |
} | |
} | |
} | |
&:checked + .btn { | |
background-color: @brand-danger; | |
color: #fff; | |
> em { | |
background-color: #fff; | |
color: @brand-danger; | |
&:before { | |
opacity: 1; | |
} | |
} | |
} | |
} | |
} | |
.btn-switch-primary { | |
.btn-switch-variant(@brand-primary); | |
} | |
.btn-switch-success { | |
.btn-switch-variant(@brand-success); | |
} | |
.btn-switch-info { | |
.btn-switch-variant(@brand-info); | |
} | |
.btn-switch-warning { | |
.btn-switch-variant(@brand-warning); | |
} | |
.btn-switch-danger { | |
.btn-switch-variant(@brand-danger); | |
} | |
.btn-switch-variant(@color) { | |
& > input[type="checkbox"] { | |
+ .btn { | |
border-color: @color; | |
color: @color; | |
> em { | |
border-color: @color; | |
} | |
} | |
&:checked + .btn { | |
background-color: @color; | |
> em { | |
color: @color; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment