使表单按钮/文本字段在所有浏览器中具有相同的高度?
我有以下 css 和 html (深入到要点。可以在此处找到带有其他样式的完整代码:我将这个 css 粘贴到 jsfiddle 上: http://jsfiddle.net/BwhvX/ ,但这足以重现问题)
css:
* {
margin: 0px;
padding: 0px;
font-size: 13px;
line-height: 15px;
border: none;
}
input[type="submit"]::-moz-focus-inner {
border: 0;
}
#search .text, #search .button {
border: 1px solid red;
}
html:
<form method="post" id="search" action="">
<p><input type="text" class="text" value="" name="suche"><input type="submit" class="button" value="Suchen"></p>
</form>
这就是 firefox 渲染的方式:
这就是 chrome 渲染的方式:
我想要两个表单元素在所有浏览器中具有相同的高度。在我看来,就像应用了一些默认样式,我需要手动重置,就像我在本例中为 Firefox 所做的那样。 在 Chrome 开发者工具中,一个高度为 16 像素,一个高度为 17 像素,但我无法看到它来自哪里,它只是计算出来的。应用的样式(向我展示的)是相同的。
I have the following css and html (drilled down to the essentials. The full code with additional styles can be found here: I have this css I pasted on jsfiddle: http://jsfiddle.net/BwhvX/ , this is however enough to reproduce the problem)
css:
* {
margin: 0px;
padding: 0px;
font-size: 13px;
line-height: 15px;
border: none;
}
input[type="submit"]::-moz-focus-inner {
border: 0;
}
#search .text, #search .button {
border: 1px solid red;
}
html:
<form method="post" id="search" action="">
<p><input type="text" class="text" value="" name="suche"><input type="submit" class="button" value="Suchen"></p>
</form>
this is how firefox renders:
this is how chrome renders:
i want the two form elements to have the same height in all browsers. looks to me like some default style is applied, that i manually need to reset like i did for firefox in this example.
in chrome developer tools one has height 16 and one height 17 px but i am not able to see where it comes from, its just calculated. the applied styles (that are shown to me) are the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
更改:
或添加类似以下内容:
不要问为什么)
和。 Safari 需要特殊修复。但看起来不错
change:
or add something like:
don't ask why)
and. safari need special fixes. but looks well
我在 normalize.css 中找到了这个,它为我解决了这个问题:
I found this in normalize.css that solved it for me:
尝试通过给予
Try By giving
通常,以下其中一项在过去使用 Firefox 浏览器对我有用。
Usually one of these below has worked for me in the past using firefox browser.
如果您指定高度而不是行高,它们将正确渲染。 height 跨浏览器表现良好;行高没有。
If you specify height instead of line-height, they will render correctly. height behaves well cross-browser; line-height does not.
Firefox 也有同样的问题,设置 line-height:normal 没有帮助。在输入和按钮元素上设置相同的填充值帮助了我。
Had the same issue with firefox, setting line-height:normal didn’t help. Setting identitcal padding values on both, the input and button element, helped me out.
CSS3 具有 box-sizing 属性。将其值设置为 border-box,告诉浏览器该元素的边框宽度和填充应包含在元素的高度中,然后可以轻松设置高度本身:
这适用于 html 也选择 元素。
CSS3 has the box-sizing property. Setting it's value to border-box, you tell the browser that the element's border-width and padding should be included into element's height, and then may easily set the height itself:
This works for html select elements as well.