I'm working on a web page, and I want custom-styled <button>
tags. So with CSS, I said: border: none
. Now it works perfectly in safari, but in chrome, when I click one of the buttons, it puts an annoying blue border around it. I thought button:active { outline: none }
or button:focus { outline:none }
would work, but neither do. Any ideas?
This is what it looks like before being clicked (and how I want it to still look after being clicked):
And this is the border I'm talking about:
Here is my CSS:
button.launch {
background-color: #F9A300;
border: none;
height: 40px;
padding: 5px 15px;
color: #ffffff;
font-size: 16px;
font-weight: 300;
margin-top: 10px;
margin-right: 10px;
}
button.launch:hover {
cursor: pointer;
background-color: #FABD44;
}
button.change {
background-color: #F88F00;
border: none;
height: 40px;
padding: 5px 15px;
color: #ffffff;
font-size: 16px;
font-weight: 300;
margin-top: 10px;
margin-right: 10px;
}
button.change:hover {
cursor: pointer;
background-color: #F89900;
}
button:active {
outline: none;
border: none;
}
Add this in your CSS file.
This is an issue in the Chrome family and has been there forever.
A bug has been raised https://bugs.chromium.org/p/chromium/issues/detail?id=904208
It can be shown here: https://codepen.io/anon/pen/Jedvwj as soon as you add a border to anything button-like (say role="button" has been added to a tag for example) Chrome messes up and sets the focus state when you click with your mouse.
I highly recommend using this fix: https://github.com/wicg/focus-visible.
Just do the following
Add the script to your html:
or import into your main entry file if using webpack or something similar:
then put this in your css file:
You can just set:
but if you have a large number of users, you're disadvantaging those who cannot use mice or those who just want to use their keyboard for speed.
In my instance of this problem I had to specify
box-shadow: none
For anyone using Bootstrap and having this problem, they use :active:focus as well as just :active and :focus so you'll need:
Hopefully saved someone some time figuring that one out, banged my head for bit wondering why such a simple thing wasn't working.
If you want to delete same effect in input, you could add the following code as well as button.
Don't forget the
!important
declaration, for a better resultA rule that has the !important property will always be applied no matter where that rule appears in the CSS document.