Reputation: 2860
I have a button group as below:
HTML
<div class="btn-group">
<button type="button" class="btn btn-default btn-xs red-outline-button"> Sync </button>
<button type="button" class="btn btn-default btn-xs gold-outline-button" data-toggle="dropdown">New PG </button>
<ul class="dropdown-menu">
<li><a href="#"> Test1</a></li>
<li><a href="#"> Test2</a></li>
</ul>
</div>
CSS:
.red-outline-button:hover {
border-color: #C4213C;
background-color: #f8d3d9;
color: #000
}
.gold-outline-button:hover {
border-color: #B3892F;
background-color: #f4ebd7;
color: #000;
}
The above works. When I hover the mouse over the buttons, the color changes. However, When I click and hold or click the second button to reveal the dropdown, then, the color switches back to the default gray.
I've tried .red-outline-button:active
but that did not help.
My question is, what is the right way to set css colour when:
Upvotes: 2
Views: 4399
Reputation: 860
This would fix it click is another event will not take hover properties
.red-outline-button:hover,.red-outline-button:active,.red-outline-button:focus {
border-color: #C4213C;
background-color: #f8d3d9;
color: #000
}
.gold-outline-button:hover,.gold-outline-button:active,.gold-outline-button:focus {
border-color: #B3892F;
background-color: #f4ebd7;
color: #000;
}
Upvotes: 0
Reputation: 1093
Just add .gold-outline-button:focus
to the selector and !important
the the styles to override the default Bootstrap styles.
e.g.
.gold-outline-button:hover, .gold-outline-button:focus {
border-color: #B3892F !important;
background-color: #f4ebd7 !important;
color: #000 !important;
}
This should solve both Problems. See it in action here: https://jsfiddle.net/sytc4pc5/
Upvotes: 0
Reputation: 7013
You need to override the default Bootstrap classes:
.btn-default.focus, .btn-default:focus
This will work in case you don't want to override all:
.gold-outline-button:hover, .gold-outline-button.focus, .gold-outline-button:focus {
border-color: #B3892F;
background-color: #f4ebd7;
color: #000;
}
Working demo: http://www.bootply.com/Li7tkXlF9P
Hope it helps you. :)
Upvotes: 2