我的按钮都有一个高亮后,我点击他们。这是Chrome。
<button class="btn btn-primary btn-block">
<span class="icon-plus"></span> Add Page
</button>
我正在使用带有主题的Bootstrap,但我非常确定这不是它:我以前在另一个项目中注意到这一点。
如果我使用<a>标签而不是<button>,它就会消失。为什么?如果我想使用<button>,我怎么让它消失呢?
我的按钮都有一个高亮后,我点击他们。这是Chrome。
<button class="btn btn-primary btn-block">
<span class="icon-plus"></span> Add Page
</button>
我正在使用带有主题的Bootstrap,但我非常确定这不是它:我以前在另一个项目中注意到这一点。
如果我使用<a>标签而不是<button>,它就会消失。为什么?如果我想使用<button>,我怎么让它消失呢?
当前回答
虽然这里提供的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,也用于其他控件,所以如果你想使用它们和/或这个特定的变量不适合你,可能需要更多的研究。
其他回答
我找到了解决办法。 当我们聚焦时,bootstrap使用box-shadow,所以我们只是禁用它(声誉不够,无法上传图像:)。
我添加
.btn:focus{
box-shadow:none !important;
}
它的工作原理。
这对我很管用。 我创建了一个自定义类,覆盖必要的CSS。
.custom-button:focus {
outline: none !important;
border: none !important;
-webkit-box-shadow: none !important;
box-shadow: none !important;
}
-webkit-box-shadow适用于Chrome和safari浏览器。
试试其中一个吧:
大纲:0; 或 大纲:0 px; 或 大纲:没有;
而且 (美元).trigger(“模糊”);
我在上面的评论中提到了这一点,但为了清晰起见,有必要把它作为一个单独的答案列出。只要你不需要在按钮上设置焦点,你可以在它应用任何CSS效果之前使用焦点事件删除它:
$('buttonSelector').focus(function(event) {
event.target.blur();
});
这避免了在使用click事件时可以看到的闪烁。这确实限制了界面,并且您将无法选择按钮,但这在所有应用程序中都不是问题。
这样效果最好
.btn-primary.focus, .btn-primary:focus {
-webkit-box-shadow: none!important;
box-shadow: none!important;
}