Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the button color when it is active using bootstrap?

Tags:

I am using bootstrap 3. I want to change button color when I click on button.I mean button should be in different color when it is selected. How can I do this using css?

My codes are :

<div class="col-sm-12" id="">     <button type="submit" class="btn btn-warning" id="1">Button1</button>     <button type="submit" class="btn btn-warning" id="2">Button2</button> </div> 
like image 893
Priyank Dey Avatar asked Feb 25 '15 06:02

Priyank Dey


People also ask

How can I change Bootstrap active button color?

The default color for btn-success is #5cb85c. All you have to do is inspect it with DevTools or search your bootstrap stylesheet to find all the rules that pertain to this class and change whatever you need in your own stylesheet to override them.

How do I change the color of an active button in CSS?

To change the background color of the button, use the CSS background-color property and give it a value of a color of your taste. In the . button selector, you use background-color:#0a0a23; to change the background color of the button.


1 Answers

CSS has different pseudo selector by which you can achieve such effect. In your case you can use

:active : if you want background color only when the button is clicked and don't want to persist.

:focus: if you want background color untill the focus is on the button.

button:active{     background:olive; } 

and

button:focus{     background:olive; } 

JsFiddle Example

P.S.: Please don't give the number in Id attribute of html elements.

like image 99
Sachin Avatar answered Sep 28 '22 02:09

Sachin