gpt4 book ai didi

How to remove outline border from input button(如何从输入按钮中移除轮廓边框)

转载 作者:bug小助手 更新时间:2023-10-25 12:44:46 27 4
gpt4 key购买 nike



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?

当我点击其他边框消失的地方时,我试图使用onFocus:None,但这并不起作用。当我点击它时,如何让这个丑陋的按钮边框消失?




input[type=button] {
width: 120px;
height: 60px;
margin-left: 35px;
display: block;
background-color: gray;
color: white;
border: none;
}

<input type="button" value="Example Button">




更多回答

looks fine on my mozilla browser

在我的Mozilla浏览器上看起来很好

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?

焦点矩形应该帮助用户观察到点击是有效的,从而防止他意外点击两次。那么,你确定你是在解决问题,而不是制造问题吗?

A good read a11yproject.com/posts/never-remove-css-outlines

一本好书a11yproject.com/posts/never-remove-css-outlines

优秀答案推荐

Using outline: none; you can remove that border in chrome.

使用Outline:None;您可以删除Chrome中的边框。


<style>
input[type=button] {
width: 120px;
height: 60px;
margin-left: 35px;
display: block;
background-color: gray;
color: white;
border: none;
outline: none;
}
</style>


Focus outline in Chrome and FF:

Chrome和FF中的焦点轮廓:


Remove Chrome button outline in CSS Remove Firefox button outline in CSS


removed button focus outline:

已删除按钮焦点轮廓:


Button without outline in CSS


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

/*
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.

将按钮的轮廓和框阴影属性都设置为None,并使它们变得重要。


input[type=button] {
outline: none !important;
box-shadow: none !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.

为了避免在更改焦点的Outline属性时引起的问题,是在输入按钮上的用户选项卡上或单击它时提供视觉效果。


In this case is a submit type, but you can apply to a type="button" too.

在本例中是提交类型,但您也可以应用于a type=“Button”。




input[type=submit]:focus {
outline: none !important;
background-color: rgb(208, 192, 74);
}





Given the html below:

给定下面的html:



<button class="btn-without-border"> Submit </button>


In the css style do the following:

在css样式中,执行以下操作:



.btn-without-border:focus {
border: none;
outline: none;
}


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.

正如许多其他人提到的,选择器:Focus{Outline:None;}将删除该边框,但该边框是一个关键的可访问性功能,允许键盘用户找到按钮,不应删除。



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.

由于您的关注点似乎是美学上的,您应该知道您可以更改轮廓的颜色、样式和宽度,使其更适合您的站点样式。



selector:focus {
outline-width: 1px;
outline-style: dashed;
outline-color: red;
}


Shorthand:

速记:



selector:focus {
outline: 1px dashed red;
}


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.

在标准的Web开发中,删除nessorry可访问事件不是一个好主意。无论哪种方式,如果您正在寻找解决方案,那么仅删除轮廓并不能解决问题。您还必须去除蓝色阴影。对于特定的场景,使用单独的类名将此特殊样式隔离到您的按钮。



.btn.focus, .btn:focus {
outline: 0;
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, .25);
}


Better do this

最好还是这样做



.remove-border.focus, .remove-border:focus {
outline: 0;
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, .25);
}


Removing the outline is an accessibility nightmare. People tabbing using keyboards will never know what item they're on.

删除大纲是易访问性的噩梦。使用键盘上网的人永远不会知道他们在什么项目上。



Best to leave it, as most clicked buttons will take you somewhere anyway, or if you HAVE to remove the outline then isolate it a specific class name.

最好离开它,因为大多数被点击的按钮都会把你带到某个地方,或者如果你必须删除轮廓,那么就用一个特定的类名来隔离它。



.no-outline {
outline: none;
}


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.

使用键盘时恢复轮廓的另一种方法是使用:Focus-Visible。然而,这在IE上不起作用:https://caniuse.com/?search=focus-visible.



Since Chrome and Mozilla added this line not only around buttons but also around linked text, I use on my site this:

由于Chrome和Mozilla不仅在按钮周围添加了这条线,而且在链接文本周围也添加了这条线,所以我在我的网站上使用了以下内容:


a:focus {outline: none;
}

Works for both browsers, links, and buttons.

适用于浏览器、链接和按钮。


Btw, this did not (27.4.2021):

顺便说一句,这并没有(27.4.2021):


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


It's also good note that outline: none can be applied to both <button> tags and input[type=button] to remove the browser-applied border on click.

还需要注意的是,Outline:None可以同时应用于



Use the below css:

使用下面的css:


.btn {
border: none !important;
background-color: white;
}

Try with this, you have to make

试着用这个,你必须做


border: none !important

更多回答

On Chrome, I had to add outline: none; rule to input[type="button"]:focus rather than input[type="button"].

在Chrome上,我必须添加Outline:None;规则输入[type=“Button”]:焦点而不是输入[type=“Button”]。

Works in Microsoft Edge too

也可在Microsoft Edge中使用

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; }

我在外部css中为整个应用程序设置了这个按钮样式。如果您想忽略它,您可以在每个按钮中使用#id在css中进行操作:#Button-Tyle{Outline:0;}或者对所有按钮使用相同样式,但每个按钮中不使用#id,这里有一个演示链接:Input[type=“Button”]{宽度:70px;高度:30px;边距-左:72px;边距-顶部:15px;显示:块;背景颜色:灰色;颜色:白色;边框:无;轮廓:0;}

To remove blue background color onclick i added -> *{ -webkit-tap-highlight-color: transparent !important; }

要删除蓝色背景色onClick,我添加了->*{-webkit-点击-高亮显示-COLOR:透明!重要;}

This worked first time perfectly - Thanks!

这是第一次完美的工作-谢谢!

The box-shadow works for me on Edge, nice : )

长方体阴影在Edge上很适合我,不错:)

I think the asker already tried this, after all, the question says tried onfocus none, but didn't help.

我想提问者已经尝试过了,毕竟,问题是没有尝试聚焦,但没有帮助。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com