My buttons all have a highlight around them after I click them. This is in Chrome.
We were suffering a similar problem and noticed that Bootstrap 3 doesn't have the problem on their tabs (in Chrome). It looks like they're using outline-style which allows the browser to decide what best to do and Chrome seems to do what you want: show the outline when focused unless you just clicked the element.
Support for outline-style
is hard to pin down since the browser gets to decide what that means. Best to check in a few browsers and have a fall-back rule.
Although it's easy to just remove outline for all focused buttons (as in user1933897's answer), but that solution is bad from the accessibility point of view (for example, see Stop Messing with the Browser's Default Focus outline)
On the other hand, it's probably impossible to convince your browser to stop styling your clicked button as focused if it thinks that it's focused after you clicked on it (I'm looking at you, Chrome on OS X).
So, what can we do? A couple options come to my mind.
1) Javascript (jQuery): $('.btn').mouseup(function() { this.blur() })
You're instructing your browser to remove the focus around any button immediately after the button is clicked. By using mouseup
instead of click
we're keeping the default behavior for keyboard-based interactions (mouseup
doesn't get triggered by keyboard).
2) CSS: .btn:hover { outline: 0 !important }
Here you turn off outline for hovered buttons only. Obviously it's not ideal, but may be enough in some situations.
Can't believe nobody has posted this yet.
Use a label instead of a button.
<label type="button" class="btn btn-primary btn-block">
<span class="icon-plus"></span> Add Page
</label>
Fiddle
For people wanting a pure css way to do that:
:focus:not(:focus-visible) { outline: none }
This could also work for link and so on, and bonus, it keeps the keyboard accessibilities. Lastly it is ignored by browsers that don’t support :focus-visible
I find a solution. when we focus, bootstrap use box-shadow, so we just disable it(not enough reputation, cannot upload image :( ).
I add
.btn:focus{
box-shadow:none !important;
}
it works.
This works best
.btn-primary.focus, .btn-primary:focus {
-webkit-box-shadow: none!important;
box-shadow: none!important;
}