查看这个按钮和锚的代码示例:http://jsbin.com/ecitex/2/edit
我试图使它们在所有浏览器中都相同。但仍然存在差异,而且每个浏览器(尝试过的chrome、safari、firefox、ie8)都有不同的差异。
我缺少哪些css规范化?
更新:
根据建议:
我添加了line-height: 50px
(尽管我的用户代理(chrome)的line-height
元素的默认值是button
,但它仍然垂直居中文本-如何居中?!)
我添加了normal
来规范化鼠标光标。
http://jsbin.com/ecitex/11/edit
那么,现在在firefox中查看结果:注意按钮上的填充吗?
然后看看ie8中的结果:哇哦,注意到这两个是如何完全完全不同的吗?啊!
更新2:
看来IE的问题是已知的,是无法解决的:http://www.quirksmode.org/css/tests/mozie_button2.html
不过,我没有在火狐的填充上找到任何东西。(quirksmode文章提到了mozilla的一个问题,但这是另一个问题。)
更新3:
太棒了,我们修复了firefox的问题:http://jsbin.com/ecitex/15/edit
好吧,到目前为止,每一个答案都是解决方案的一部分,所以没有一个真正的最佳答案。我会给这个人最好的回答,要么:
解释了为什么我们必须在cursor: pointer
中指定line-height: 50px
以垂直居中文本,而a
具有仅button
的垂直居中文本。
为IE问题提供解决方案。
最佳答案
您可以使用以下方法删除Firefox中的额外填充:
button::-moz-focus-inner {
border: 0;
padding: 0;
}
这里有一个很好的解释,从埃里克迈耶关于线的高度,希望解释为什么你需要显式地设置为50像素:http://meyerweb.com/eric/thoughts/2008/05/06/line-height-abnormal/。
下面是一些新的css,它修复了ie中的字体大小问题:
button, a {
display: inline-block;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
margin: 10px 0;
padding: 0px;
height: 50px;
border-width: 0;
background-color: Red;
color: White;
font-family: sans-serif;
font-weight: normal;
font-size: inherit;
text-decoration: none;
line-height: 50px;
cursor: pointer;
font-size: 100%;
}
button {
#width:0px;
overflow: visible;
}
button::-moz-focus-inner {
border: 0;
padding: 0;
}