当我点击其他地方的边界消失,我试图使用onfocus: none,但这没有帮助。如何使这个丑陋的按钮边界消失时,我点击它?

输入(type =按钮){ 宽度:120 px; 高度:60 px; margin-left: 35 px; 显示:块; 背景颜色:灰色; 颜色:白色; 边界:没有; } <input type="button" value="Example button" >


使用outline: none;你可以在铬中删除边界。

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

Chrome和FF中的焦点轮廓:

删除按钮焦点轮廓:

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

这对我来说很简单:)

*:focus {
    outline: 0 !important;
}

outline属性就是您所需要的。它是在单个声明中设置以下每个属性的简写:

outline-style outline-width 边框色

你可以使用outline: none;,这是公认答案中的建议。如果你想,你也可以说得更具体:

button {
    outline-style: none;
}

这个方法对我很管用

button:focus {
    border: none;
    outline: none;
}

删除大纲是可访问性的噩梦。使用键盘的人永远不知道他们在敲什么。

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

.no-outline {
  outline: none;
}

然后,您可以在需要时应用该类。


给定下面的html:

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

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

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

此代码将删除按钮边框,并在单击按钮时禁用按钮边框焦点。


正如许多人提到的,selector:focus {outline: none;}将删除该边框,但该边框是一个关键的可访问性特性,允许键盘用户找到按钮,不应该被删除。

由于您关心的似乎是一个美学问题,您应该知道您可以更改轮廓的颜色、样式和宽度,使其更适合您的网站样式。

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

速记:

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

button:focus{outline:none !important;}

如果在Bootstrap中使用,则重要


这比你想象的要简单得多。当按钮被聚焦时,应用outline属性,如下所示:

button:focus {
    outline: 0 !important;
}

但是当我使用none值时,它对我不起作用。


为了避免在更改焦点上的outline属性时所造成的问题,就是在用户按Tab键输入或点击它时给人一种视觉效果。

在这个例子中是一个提交类型,但是你也可以应用到type="button"。

输入(type =提交):{焦点 大纲:不重要; Background-color: rgb(208,192,74); }


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

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

最好这样做

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

将按钮的轮廓和框影属性都设置为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.

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


同样值得注意的是outline: none可以应用于<button>标签和input[type=button]来删除浏览器应用的单击边框。


由于Chrome和Mozilla不仅在按钮周围添加了这一行,而且在链接文本周围也添加了这一行,我在我的网站上使用这个:

a:focus {outline: none;
}

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

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

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