删除 Firefox 中额外的按钮间距/填充
请参阅此代码示例: http://jsfiddle.net/Z2BMK/
Chrome/IE8 看起来像这样
Firefox 看起来像这样
我的 CSS 是
button {
padding:0;
background:#080;
color:white;
border:solid 2px;
border-color: #0c0 #030 #030 #0c0;
margin:0;
}
如何更改代码示例以使按钮在两个浏览器中相同?我不想使用基于 JavaScript 的超链接,因为它们不能与键盘上的空格键一起使用,而且它必须有一个 href
URL,这不是一个干净的处理方式。
我的解决方案,自 Firefox 13
button::-moz-focus-inner { margin: -1px;填充:0;边框宽度:1px; }
See this code example: http://jsfiddle.net/Z2BMK/
Chrome/IE8 look like this
Firefox looks like this
My CSS is
button {
padding:0;
background:#080;
color:white;
border:solid 2px;
border-color: #0c0 #030 #030 #0c0;
margin:0;
}
How can I change the code sample to make the button the same in both browsers? I do not want to use JavaScript based hyperlinks because they do not work with space bar on keyboard and it has to have an href
URL which is not a clean way to handle things.
My solution, since Firefox 13
button::-moz-focus-inner { margin: -1px; padding: 0; border-width: 1px; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@thirtydot 答案的更正版本:
关于 Firefox 87:
button::-moz-focus-inner
中的button
不能是一个类。 (例如.mybutton::-moz-focus-inner
不起作用)必须有一个
button { padding:0px;边框:0px; }
样式也存在(该样式可以为每个类指定)。Corrected version of @thirtydot's answer:
Regarding Firefox 87:
button
inbutton::-moz-focus-inner
cannot be a class. (E.g..mybutton::-moz-focus-inner
does not work)There must be a
button { padding:0px; border: 0px; }
style present as well (This style can be given per class).添加以下内容:
http://jsfiddle.net/thirtydot/Z2BMK/1/
包括 <上面的 code>border 规则对于按钮在两种浏览器中看起来相同是必要的,而且当按钮在 Firefox 中
active
时,它也会删除虚线轮廓。许多开发人员摆脱了这种虚线轮廓,选择用视觉上更友好的东西替换它。Add this:
http://jsfiddle.net/thirtydot/Z2BMK/1/
Including the
border
rule above is necessary for buttons to look the same in both browsers, but also it removes the dotted outline when the button isactive
in Firefox. Lots of developers get rid of this dotted outline, optionally replacing it with something more visually friendly.将其修复在输入元素上并添加
是简单而完美的!
To fix it on input elements as well add
is simple perfect!