我的按钮都有一个高亮后,我点击他们。这是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>,我怎么让它消失呢?
当前回答
这里有两种可能的解决方案。
1.) 按钮类型=“按钮” 类名称=“btn-cart”onClick{(event)=>this.blur(event)}
2.)按钮类型="按钮" className="btn-cart" onclick={this.blur}
这两种解决方案都将删除按钮周围突出显示的部分 即-> blur()有自己的规范,它删除突出显示的部分周围。
其他回答
对于sass用户,引导4应该通过重写变量来操作。
如果你想禁用按钮周围焦点上的框影:
$btn-focus-box-shadow: none;
你也可以禁用输入周围焦点上的框影:
$input-focus-box-shadow: none;
或者两者都有一个变量:
$input-btn-focus-box-shadow: none;
我找到了解决办法。 当我们聚焦时,bootstrap使用box-shadow,所以我们只是禁用它(声誉不够,无法上传图像:)。
我添加
.btn:focus{
box-shadow:none !important;
}
它的工作原理。
真不敢相信居然没人贴出来。
使用标签而不是按钮。
<label type="button" class="btn btn-primary btn-block">
<span class="icon-plus"></span> Add Page
</label>
小提琴
如果你使用规则:focus {outline: none;}来删除轮廓,则该链接或控件将是可聚焦的,但对于键盘用户没有焦点指示。使用onfocus="blur()"这样的JS删除它的方法更糟糕,会导致键盘用户无法与控件交互。
你可以使用的一些技巧,包括添加:focus {outline: none;}规则,并在检测到键盘交互时再次删除它们。林赛·埃文斯为此做了一个lib: https://github.com/lindsayevans/outline.js
但我更喜欢在html或body标签上设置一个类。并在CSS文件中控制何时使用它。
例如(内联事件处理程序仅用于演示目的):
<html>
<head>
<style>
a:focus, button:focus {
outline: 3px solid #000;
}
.no-focus a, .no-focus button {
outline: none;
}
</style>
</head>
<body id="thebody"
onmousedown="document.getElementById('thebody').classList.add('no-focus');"
onkeydown="document.getElementById('thebody').classList.remove('no-focus');">
<p>This her is <a href="#">a link</a></p>
<button>Click me</button>
</body>
</html>
我确实整理了一个Pen: http://codepen.io/snobojohan/pen/RWXXmp
但要注意存在性能问题。这将强制用户每次在鼠标和键盘之间切换时重新绘制。更多关于避免不必要的油漆http://www.html5rocks.com/en/tutorials/speed/unnecessary-paints/
试试其中一个吧:
大纲:0; 或 大纲:0 px; 或 大纲:没有;
而且 (美元).trigger(“模糊”);