Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap button focus

I styled my button everything is cool but can't change the blue color on click.

<button type="button" class="btn btn-primary">Log In</button>
.btn.btn-primary:focus {
  background-color: and here color
} 

doesn't work

like image 665
K4NU 420 Avatar asked Nov 01 '25 03:11

K4NU 420


1 Answers

The hover state has priority over the active or focus. You can see it on the snippet as both element has a color change for active, but only on for hover.

.btn:active { background-color: red }
.btn.btn-primary:hover { background-color: green }
<button type="button" class="btn btn-primary">With hover</button>
<button type="button" class="btn btn-secondary">No hover</button>

To solve this, you need to specify the order, and be clear in your selectors. hover selector needs to be before the active selector.

.btn.btn-primary:hover { background-color: green }
.btn.btn-primary:active { background-color: red }
<button type="button" class="btn btn-primary">Button</button>
like image 151
Gerardo BLANCO Avatar answered Nov 02 '25 17:11

Gerardo BLANCO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!