我的按钮都有一个高亮后,我点击他们。这是Chrome。

<button class="btn btn-primary btn-block">
    <span class="icon-plus"></span> Add Page
</button>

我正在使用带有主题的Bootstrap,但我非常确定这不是它:我以前在另一个项目中注意到这一点。

如果我使用<a>标签而不是<button>,它就会消失。为什么?如果我想使用<button>,我怎么让它消失呢?


当前回答

我的理解是,焦点首先应用在onMouseDown事件之后,所以在onMouseDown中调用e.c preventdefault()可能是一个干净的解决方案,取决于你的需求。这当然是一个可访问性友好的解决方案,但显然它调整了鼠标点击的行为,这可能与您的web项目不兼容。

我目前正在使用这个解决方案(在一个反应引导项目中),我没有收到一个焦点闪烁或按钮点击后保留的焦点,但我仍然能够标签我的焦点和视觉上可视化相同按钮的焦点。

其他回答

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

这将在点击时删除轮廓,但在点击时保持焦点(对于a11y)

直接在HTML标签中(在您可能想要在设计的其他地方留下引导主题的场景中)..

尝试的例子..

<button style="border: transparent;">
<button style="border: 1px solid black;">

. .等。这取决于你想要的效果。

虽然这里提供的CSS解决方案有效,

对于任何喜欢使用Bootstrap 4方式的人,就像官方Bootstrap主题指南中建议的那样, 这应该会有帮助:

按你们的习惯。SCSS文件(参见上面的指南^),其中您添加了您的变量覆盖,添加以下变量来删除按钮的盒子阴影:

// import bootstrap's variables & functions to override them
@import "node_modules/bootstrap/scss/functions";
@import "node_modules/bootstrap/scss/variables";
@import "node_modules/bootstrap/scss/mixins";

// override the variables you want (you can look them up in node_modules/bootstrap/scss/variables file, they're the ones that have the !default keyword at the end)
$btn-focus-box-shadow: none;

// option A: include all of Bootstrap (see the above guide for other options)
@import "node_modules/bootstrap/scss/bootstrap";

这对我很有用。

请注意,在bootstrap的变量文件中有许多变量用于box-shadow,也用于其他控件,所以如果你想使用它们和/或这个特定的变量不适合你,可能需要更多的研究。

迟到了,但谁知道这也许能帮到谁呢。 CSS看起来像这样:

.rhighlight{
   outline: none !important;
   box-shadow:none
}

HTML看起来像这样:

<button type="button" class="btn btn-primary rHighlight">Text</button> 

这样你就可以保留btn和它相关的行为。

我有同样的问题使用<a>作为按钮,我发现我错过了一个工作区添加attr类型=“按钮”使它的行为正常为我至少。

<a type=“巴顿”类=“bmr btn-primary”>释放我!< / a >