content logo

Bootstrap Toggle Switches:

Change Background Color with Bootstrap Switch

Website personalization is the process of providing your visitors with options to create customized experiences for themselves in a website. Offering customization in a website is a great way to ensure your visitors are satisfied since they can choose how they want your website to look rather than being provided with a single, broad experience for everyone. This allows sites to present visitors with unique and special experiences that were tailored to match their desires and needs. One of the many things you can use to give your visitors this freedom, is a simple toggle switch. You can add a switch with different modes that the visitors can choose from. You can let them decide if they want to see fonts in a larger format, if they want grid or list view, they can choose a different layout or any other fundamental in your site.

Speaking of toggle switches, we have a beautiful change colour toggle switch which can be used as a customization option for your users. This Bootstrap beautiful switch allows your users to change background colour with switch toggle. In other words, upon activating the switch, the colour of the text below it will change to blue.

#

Toggle Switches

#

Bootsrtap Beautiful Switch

#

Change Color Toggle Switch

#

Switch Background

<!-- This script got from frontendfreecode.com -->
<div class="container my-5">
    <div class="text-center">
        <span> Normal</span>
        <label class="switch">
            <input type="checkbox" name="graduate">
            <span class="slider round"></span>
        </label>
        <span class="text-primary"> Colored</span>
    </div>
    <div class="col-md-12 ug mt-5">
        <div class="card bg-light">
            <div class="card-body text-center">
                <p class="card-text">Some text inside the normal card</p>
            </div>
        </div>
    </div>
    <div class="col-md-12 mt-5 phd" style="display: none">
        <div class="card bg-primary">
            <div class="card-body text-center">
                <p class="card-text">Some text inside the colored card</p>
            </div>
        </div>
    </div>
</div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}
.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}
input:checked + .slider {
  background-color: #2196F3;
}
input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}
.slider.round:before {
  border-radius: 50%;
}
$(document).ready(function () {
    $('[name="graduate"]').change(function () {
        if ($('[name="graduate"]:checked').is(":checked")) {
            $('.ug').hide();
            $('.phd').show();
        } else {
            $('.ug').show();
            $('.phd').hide();
        }
    });
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/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/4.2.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<style>
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}
.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}
input:checked + .slider {
  background-color: #2196F3;
}
input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}
/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}
.slider.round:before {
  border-radius: 50%;
}
</style>

</head>
<body>
<div class="container my-5">
    <div class="text-center">
        <span> Normal</span>
        <label class="switch">
            <input type="checkbox" name="graduate">
            <span class="slider round"></span>
        </label>
        <span class="text-primary"> Colored</span>
    </div>
    <div class="col-md-12 ug mt-5">
        <div class="card bg-light">
            <div class="card-body text-center">
                <p class="card-text">Some text inside the normal card</p>
            </div>
        </div>
    </div>
    <div class="col-md-12 mt-5 phd" style="display: none">
        <div class="card bg-primary">
            <div class="card-body text-center">
                <p class="card-text">Some text inside the colored card</p>
            </div>
        </div>
    </div>
</div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
$(document).ready(function () {
    $('[name="graduate"]').change(function () {
        if ($('[name="graduate"]:checked').is(":checked")) {
            $('.ug').hide();
            $('.phd').show();
        } else {
            $('.ug').show();
            $('.phd').hide();
        }
    });
});
</script>

</body>
</html>
Preview