Andrew Pullins Andrew Pullins - 10 days ago 7
CSS Question

How to hide button outline

I have this page with a lot of buttons here: https://jsfiddle.net/Android272/c150305z/

I have tried every combination of the below code but nothing will get rid of the outline.

*:focus,
button,
button:focus,
button:active {
outline: 0;
outline-width: 0;
outline: none;
outline-style: none;
}

Answer

Theoretically, one could write:

button {
    outline: none; 
}

This will remove the select border from a button. However, in this case we require !important on the outline property to prevent Bootstrap from overwriting it (seen below). I would also recommend adding cross-browser support for a known bug with Chrome and Firefox.

button {
    outline: none !important; 
}

input[type="button"]::-moz-focus-inner {
    border: 0;
}

Alternatively, Bootstrap has these styles associated with buttons on focus that you need to either remove or overwrite.

.btn.active.focus,
.btn.active:focus,
.btn.focus,
.btn:active.focus,
.btn:active:focus,
.btn:focus {
    outline: thin dotted;
    outline: 5px auto -webkit-focus-ring-color;
    outline-offset: -2px;
}

Use this to overwrite it:

.btn.active.focus,
.btn.active:focus,
.btn.focus,
.btn:active.focus,
.btn:active:focus,
.btn:focus {
    outline: none;
}    
Comments