Switchery Checkbox with text label
Switchery Checkbox with text label
by Bilal AFSAR
HTML
<link rel="stylesheet" href="maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.switchery/0.8.1/switchery.min.css">
<script src="https://code.jquery.com/jquery-1.x-git.js"></script>
<script src="maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.switchery/0.8.1/switchery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<input type="checkbox" class="js-switch">
CSS
body {
margin: 30px;
}
.switchery {
width: 160px; // your width
border: 2px solid black;
}
.switchery::before {
content: "\f00c";
color: #333;
position: absolute;
left: 70px;
top: 50%;
transform: translateY(-50%) translateX(-10%);
}
.js-switch::checked + .switchery::before {
color: #fff;
content: "\f00c";
width:100px;
left:40px;
}
JavaScript
var elem = document.querySelector('.js-switch');
var init = new Switchery(elem);
//special thanks to
// http://codepen.io/makshh/pen/zBzxyB