当我点击其他地方的边界消失,我试图使用onfocus: none,但这没有帮助。如何使这个丑陋的按钮边界消失时,我点击它?
输入(type =按钮){ 宽度:120 px; 高度:60 px; margin-left: 35 px; 显示:块; 背景颜色:灰色; 颜色:白色; 边界:没有; } <input type="button" value="Example button" >
当我点击其他地方的边界消失,我试图使用onfocus: none,但这没有帮助。如何使这个丑陋的按钮边界消失时,我点击它?
输入(type =按钮){ 宽度:120 px; 高度:60 px; margin-left: 35 px; 显示:块; 背景颜色:灰色; 颜色:白色; 边界:没有; } <input type="button" value="Example button" >
当前回答
这个方法对我很管用
button:focus {
border: none;
outline: none;
}
其他回答
同样值得注意的是outline: none可以应用于<button>标签和input[type=button]来删除浏览器应用的单击边框。
删除大纲是可访问性的噩梦。使用键盘的人永远不知道他们在敲什么。
最好离开它,因为大多数点击按钮会把你带到某个地方,或者如果你必须删除轮廓,然后把它隔离为一个特定的类名。
.no-outline {
outline: none;
}
然后,您可以在需要时应用该类。
正如许多人提到的,selector:focus {outline: none;}将删除该边框,但该边框是一个关键的可访问性特性,允许键盘用户找到按钮,不应该被删除。
由于您关心的似乎是一个美学问题,您应该知道您可以更改轮廓的颜色、样式和宽度,使其更适合您的网站样式。
selector:focus {
outline-width: 1px;
outline-style: dashed;
outline-color: red;
}
速记:
selector:focus {
outline: 1px dashed red;
}
在使用键盘时,另一种恢复轮廓的方法是使用:focus-visible。但是,这在IE:https://caniuse.com/?search=focus-visible上不起作用。
button:focus{outline:none !important;}
如果在Bootstrap中使用,则重要