当我点击其他地方的边界消失,我试图使用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" >
当前回答
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 */
}
其他回答
使用outline: none;你可以在铬中删除边界。
<style>
input[type=button] {
width: 120px;
height: 60px;
margin-left: 35px;
display: block;
background-color: gray;
color: white;
border: none;
outline: none;
}
</style>
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 */
}
为了避免在更改焦点上的outline属性时所造成的问题,就是在用户按Tab键输入或点击它时给人一种视觉效果。
在这个例子中是一个提交类型,但是你也可以应用到type="button"。
输入(type =提交):{焦点 大纲:不重要; Background-color: rgb(208,192,74); }
正如许多人提到的,selector:focus {outline: none;}将删除该边框,但该边框是一个关键的可访问性特性,允许键盘用户找到按钮,不应该被删除。
由于您关心的似乎是一个美学问题,您应该知道您可以更改轮廓的颜色、样式和宽度,使其更适合您的网站样式。
selector:focus {
outline-width: 1px;
outline-style: dashed;
outline-color: red;
}
速记:
selector:focus {
outline: 1px dashed red;
}
outline属性就是您所需要的。它是在单个声明中设置以下每个属性的简写:
outline-style outline-width 边框色
你可以使用outline: none;,这是公认答案中的建议。如果你想,你也可以说得更具体:
button {
outline-style: none;
}