Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize bootstrap switch color

How can I customize bootstrap switch color to the desired color?

I found a oncolor and offcolor but not know how to change them.

like image 948
Ebrahim Avatar asked Apr 11 '15 07:04

Ebrahim


People also ask

How do I change the color of my bootstrap switch?

In Bootstrap 4, the background color of the toggle switch is blue. This color can be changed by manipulating the custom-control-input class.

How do I change the color of a checkbox in bootstrap?

input[type=checkbox] does not not have a background-color property. You can use other ways to get your desirable result: You can use the checkbox inside a div and then style the div according to your needs.

How do I change the background color in bootstrap?

We can add background color to a div by simply adding class “bg-primary”, “bg-success”, “bg-danger”, “bg-info”, and many more as shown in the following examples.


1 Answers

According to this page every option is also a method. So you can apply onColor and OffColor like that:

$("#sw").bootstrapSwitch({onColor: 'danger'});

or like that:

$("#sw").bootstrapSwitch();
...
$("#sw").bootstrapSwitch('onColor', 'danger');

or to override the default options of the library:

$.fn.bootstrapSwitch.defaults.onColor = 'danger';

To use your own colors you need to create your own CSS class. For example, this class uses 'retroorange' name with your color:

.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-retroorange,
.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-retroorange {
  color: #fff;
  background: #ff9933;
}

Then you can use 'retroorange' in the usual way like that:

$("#sw").bootstrapSwitch({onColor: 'retroorange'});
like image 75
alemv Avatar answered Sep 18 '22 19:09

alemv