How to remove outline border from input button(如何从输入按钮中移除轮廓边框)
转载作者:bug小助手更新时间:2023-10-25 12:44:46274
When I click somewhere else the border disappears, I tried to use onfocus: none, but that didn't help. How to make this ugly button border disappear when I click on it?
The focus rectangle is supposed to help the user observe that the click was effective and thereby prevent him from accidentally clicking twice. So are you sure you are solving a problem and not creating one?
/* Accessibility (A11Y) Don't forget! User accessibility is important */ button:focus, input[type=button]:focus { /* your custom focused styles here */ }
It works for me simply :)
它对我来说很简单:)
*:focus { outline: 0 !important; }
Set both the outline and the box-shadow properties of the button to none and make them important.
The reason for setting the values to **important** is that, if you are using other CSS libraries or frameworks like Bootstrap, it might get overridden.
This one worked for me
这个对我很管用
button:focus { border: none; outline: none; }
The outline property is what you need. It's shorthand for setting each of the following properties in a single declaration:
Outline属性就是您所需要的。它是在单个声明中设置以下每个属性的快捷方式:
outline-style
outline-width
outline-color
You could use outline: none;, which is suggested in the accepted answer. You could also be more specific if you wanted:
您可以使用Outline:None;,这是公认答案中的建议。如果你愿意,你也可以说得更具体:
button { outline-style: none; }
button:focus{outline:none !important;}
add !important if it is used in Bootstrap
如果在Bootstrap中使用,请注意添加!
To avoid the problem caused when you change the outline property on a focus, is to give a visual effect when the user Tab on the input button or click on it.
This code will remove button border and will disable button border focus when the button is clicked.
此代码将移除按钮边框,并在单击按钮时禁用按钮边框焦点。
As many others have mentioned, selector:focus {outline: none;} will remove that border but that border is a key accessibility feature that allows for keyboard users to find the button and shouldn't be removed.
Since your concern seems to be an aesthetic one, you should know that you can change the color, style, and width of the outline, making it fit into your site styling better.
It's greatly simple than you think. When the button is focussed, apply the outline property, like this:
这比你想象的要简单得多。当按钮被聚焦时,应用Outline属性,如下所示:
button:focus { outline: 0 !important; }
But when I use none value, it doesn't work for me.
但是当我不使用任何值时,它对我就不起作用了。
Removing nessorry accessible event not a good idea in up to standard web developments. either way if you looking for a solution removing just the outline doesn't solve the problem. you also have to remove the blue color shadow. for specific scenarios use a separate class name to isolate the this special style to your button.
Then you can apply that class whenever you need to.
然后,您可以在需要的时候应用该类。
Another alternative to restore outline when using the keyboard is to use :focus-visible. However, this doesn't work on IE :https://caniuse.com/?search=focus-visible.
This is the only answer that worked for me, but how would you do it without !important? I've heard from a lot of sources that you should only use it only if absolutely necessary.
I did this button styling for whole application in external css. If u want ignore it u can do it with #id in css using that in each button: #button-tyle{ outline: 0; } or use same style for all buttons without #id in each button, here is a demo link: input[type="button"] { width:70px; height:30px; margin-left:72px; margin-top:15px; display:block; background-color:gray; color:white; border: none; outline: 0; }
我是一名优秀的程序员,十分优秀!