当我点击其他地方的边界消失,我试图使用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" >
当前回答
给定下面的html:
<button class="btn-without-border"> Submit </button>
在css样式中执行以下操作:
.btn-without-border:focus {
border: none;
outline: none;
}
此代码将删除按钮边框,并在单击按钮时禁用按钮边框焦点。
其他回答
outline属性就是您所需要的。它是在单个声明中设置以下每个属性的简写:
outline-style outline-width 边框色
你可以使用outline: none;,这是公认答案中的建议。如果你想,你也可以说得更具体:
button {
outline-style: none;
}
这个方法对我很管用
button:focus {
border: none;
outline: none;
}
删除大纲是可访问性的噩梦。使用键盘的人永远不知道他们在敲什么。
最好离开它,因为大多数点击按钮会把你带到某个地方,或者如果你必须删除轮廓,然后把它隔离为一个特定的类名。
.no-outline {
outline: none;
}
然后,您可以在需要时应用该类。
这对我来说很简单:)
*:focus {
outline: 0 !important;
}
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 */
}