<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/pretty-checkbox@3.0/dist/pretty-checkbox.min.css" />
<br/><br/><br/><br/>
<div class="pretty p-default">
<input type="checkbox" />
<div class="state">
<label>Check</label>
</div>
</div>
<!-- add class p-switch -->
<div class="pretty p-switch">
<input type="checkbox" />
<div class="state">
<label>Outline</label>
</div>
</div>
<!-- add class p-switch -->
<div class="pretty p-switch p-fill">
<input type="checkbox" />
<div class="state">
<label>Fill</label>
</div>
</div>
<!-- add class p-switch -->
<div class="pretty p-switch p-slim">
<input type="checkbox" />
<div class="state">
<label>Slim</label>
</div>
</div>
//@import '~pretty-checkbox/src/pretty-checkbox.scss';
body {
margin: 20% 0 0 30%;
}
#container{background:#ebebeb;}
.switch{
border:none;
background:left no-repeat;
width:105px;
height:46px;
padding:0;
margin:0;
}
.on, .off{
width:50px;
height:40px;
display:inline-block;
cursor:pointer;
}
.result{display:none;}
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #34A7C1; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 56px;
border: 2px solid #999999; border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
.result2{display:none;}
View Compiled
$(document).ready(function(){
$('.switch').css('background', 'url("http://papermashup.com/demos/jquery-switch/switch.png")');
$('.on_off').css('display','none');
$('.on, .off').css('text-indent','-10000px');
$("input[name=on_off]").change(function() {
var button = $(this).val();
if(button == 'off'){ $('.switch').css('background-position', 'right'); }
if(button == 'on'){ $('.switch').css('background-position', 'left'); }
$('.result span').html(button);
$('.result').fadeIn();
});
$('input.lcs_check').lc_switch();
});
This Pen doesn't use any external CSS resources.