"Badgebox: CSS checkbox badge"
Bootstrap 4.1.1 Snippet by kodakro

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <br> <br> <br> <br> <div class="row text-center"> <label for="default" class="btn btn-default">Default <input type="checkbox" id="default" class="badgebox"><span class="badge-pill">&check;</span></label> <label for="primary" class="btn btn-primary">Primary <input type="checkbox" id="primary" class="badgebox"><span class="badge-pill">&check;</span></label> <label for="info" class="btn btn-info">Info <input type="checkbox" id="info" class="badgebox"><span class="badge-pill">&check;</span></label> <label for="success" class="btn btn-success">Success <input type="checkbox" id="success" class="badgebox"><span class="badge-pill">&check;</span></label> <label for="warning" class="btn btn-warning">Warning <input type="checkbox" id="warning" class="badgebox"><span class="badge-pill">&check;</span></label> <label for="danger" class="btn btn-danger">Danger <input type="checkbox" id="danger" class="badgebox"><span class="badge-pill">&check;</span></label> </div> </div>
/* Hiding the checkbox, but allowing it to be focused */ .badgebox { opacity: 0; } .badgebox + .badge-pill { /* Move the check mark away when unchecked */ text-indent: -999999px; /* Makes the badge's width stay the same checked and unchecked */ width: 27px; } .badgebox:focus + .badge-pill { /* Set something to make the badge looks focused */ /* This really depends on the application, in my case it was: */ /* Adding a light border */ box-shadow: inset 0px 0px 5px; /* Taking the difference out of the padding */ } .badgebox:checked + .badge-pill { /* Move the check mark back when checked */ text-indent: 0; }
// You didn't believe it hadn't used JS, uh?

Related: See More


Questions / Comments: