content logo

Bootstrap Toggle Switches:

Show/Hide Text with Bootstrap Switch

To make your website more beautiful, you should use special styles for different parts. In this code, one of these styles comes with a special feature. In addition, this switch is rectangular and the selected cell is blue. Clicking on the switch and activating it displays text, and by disabling the switch, the text disappears.

#

Bootstrap Toggle Switch

#

Beautiful Switches

#

Bootstrap Switch

#

Blue and White Switch

<!-- This script got from frontendfreecode.com -->
<br>
<div class="btn-group btn-toggle vertical-center">
    <button class="btn btn-default" data-toggle="collapse" data-target="#collapsible">On</button>
    <button class="btn btn-primary active" data-toggle="collapse" data-target="#collapsible">Off</button>
</div>
<div class="collapse vertical-center" id="collapsible" style="margin-top:50px">
    <fieldset>
        <legend>
            More options here
        </legend>

    </fieldset>
</div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
.toggleswitch {
  position: relative;
  width: 90px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}
.toggleswitch-checkbox {
  display: none;
}
.toggleswitch-label {
  display: block;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid #27A1CA;
  border-radius: 0px;
}
.toggleswitch-inner {
  display: block;
  width: 200%;
  margin-left: -100%;
  -moz-transition: margin 0.3s ease-in 0s;
  -webkit-transition: margin 0.3s ease-in 0s;
  -o-transition: margin 0.3s ease-in 0s;
  transition: margin 0.3s ease-in 0s;
}
.toggleswitch-inner:before,
.toggleswitch-inner:after {
  display: block;
  float: left;
  width: 50%;
  height: 30px;
  padding: 0;
  line-height: 26px;
  font-size: 14px;
  color: white;
  font-family: Trebuchet, Arial, sans-serif;
  font-weight: bold;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.toggleswitch-inner:before {
  content: "Yes";
  padding-left: 10px;
  background-color: #FFFFFF;
  color: #27A1CA;
}
.toggleswitch-inner:after {
  content: "No";
  padding-right: 10px;
  background-color: #FFFFFF;
  color: #666666;
  text-align: right;
}
.toggleswitch-switch {
  display: block;
  width: 25px;
  margin: 0px;
  background: #27A1CA;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 65px;
  -moz-transition: all 0.3s ease-in 0s;
  -webkit-transition: all 0.3s ease-in 0s;
  -o-transition: all 0.3s ease-in 0s;
  transition: all 0.3s ease-in 0s;
}
.toggleswitch-checkbox:checked + .toggleswitch-label .toggleswitch-inner {
  margin-left: 0;
}
.toggleswitch-checkbox:checked + .toggleswitch-label .toggleswitch-switch {
  right: 0px;
}
.vertical-center {
    margin: 0;
    position: absolute;
    left: 50%;
    -ms-transform: translateX(-50%);
    transform: translateX(-50%);
}
$('.btn-toggle').click(function() {
  $(this).find('.btn').toggleClass('active');
  if ($(this).find('.btn-primary').size() > 0) {
    $(this).find('.btn').toggleClass('btn-primary');
  }
  $(this).find('.btn').toggleClass('btn-default');
});
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>
<script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>
<script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'></script>
<style>
.toggleswitch {
  position: relative;
  width: 90px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}
.toggleswitch-checkbox {
  display: none;
}
.toggleswitch-label {
  display: block;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid #27A1CA;
  border-radius: 0px;
}
.toggleswitch-inner {
  display: block;
  width: 200%;
  margin-left: -100%;
  -moz-transition: margin 0.3s ease-in 0s;
  -webkit-transition: margin 0.3s ease-in 0s;
  -o-transition: margin 0.3s ease-in 0s;
  transition: margin 0.3s ease-in 0s;
}
.toggleswitch-inner:before,
.toggleswitch-inner:after {
  display: block;
  float: left;
  width: 50%;
  height: 30px;
  padding: 0;
  line-height: 26px;
  font-size: 14px;
  color: white;
  font-family: Trebuchet, Arial, sans-serif;
  font-weight: bold;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.toggleswitch-inner:before {
  content: "Yes";
  padding-left: 10px;
  background-color: #FFFFFF;
  color: #27A1CA;
}
.toggleswitch-inner:after {
  content: "No";
  padding-right: 10px;
  background-color: #FFFFFF;
  color: #666666;
  text-align: right;
}
.toggleswitch-switch {
  display: block;
  width: 25px;
  margin: 0px;
  background: #27A1CA;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 65px;
  -moz-transition: all 0.3s ease-in 0s;
  -webkit-transition: all 0.3s ease-in 0s;
  -o-transition: all 0.3s ease-in 0s;
  transition: all 0.3s ease-in 0s;
}
.toggleswitch-checkbox:checked + .toggleswitch-label .toggleswitch-inner {
  margin-left: 0;
}
.toggleswitch-checkbox:checked + .toggleswitch-label .toggleswitch-switch {
  right: 0px;
}
.vertical-center {
    margin: 0;
    position: absolute;
    left: 50%;
    -ms-transform: translateX(-50%);
    transform: translateX(-50%);
}
</style>

</head>
<body>
<br>
<div class="btn-group btn-toggle vertical-center">
    <button class="btn btn-default" data-toggle="collapse" data-target="#collapsible">On</button>
    <button class="btn btn-primary active" data-toggle="collapse" data-target="#collapsible">Off</button>
</div>
<div class="collapse vertical-center" id="collapsible" style="margin-top:50px">
    <fieldset>
        <legend>
            More options here
        </legend>

    </fieldset>
</div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
$('.btn-toggle').click(function() {
  $(this).find('.btn').toggleClass('active');
  if ($(this).find('.btn-primary').size() > 0) {
    $(this).find('.btn').toggleClass('btn-primary');
  }
  $(this).find('.btn').toggleClass('btn-default');
});
</script>

</body>
</html>
Preview