CSS:提交按钮看起来比文本输入和文本区域小
我刚刚注意到一个非常简单的形式的奇怪渲染。
这是我的标记/CSS: http://jsfiddle.net/a9PLM/
如您所见,文本字段和按钮共享相同的内容款式不同,但尺寸却有很大不同。
为什么会发生这种情况?
谢谢!
I just noticed this strange rendering of a very simple form.
Here's my markup/CSS: http://jsfiddle.net/a9PLM/
As you can see, text fields and the button share the same styles but their size is quite different.
Why does this happen?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是因为
和
使用的盒模型不同/
<文本区域>
。您可以通过使用 CSS 指定盒子模型来使它们相同:您可以在此处阅读有关盒子模型的更多信息:https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model
我编辑了您的jsFiddle 来显示它的工作原理: jsFiddle 演示
This is because of the box model being used is different for the
<input type="submit">
and the<input type="text">
/<textarea>
. You can make the box models the same by specifying them with CSS:You can read more about box models here: https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model
I edited your jsFiddle to show it working: jsFiddle demo
我认为这是一个浏览器渲染问题......按钮的显示方式与文本输入不同。
要修复此问题,请将其添加到您的 CSS
示例: http://jsfiddle.net /jasongennaro/a9PLM/1/
I think this is a browser rendering issue... with buttons being displayed differently than text inputs.
To fix, add this to your css
Example: http://jsfiddle.net/jasongennaro/a9PLM/1/
文本字段上的填充为其两侧提供了额外的空间。将输入和文本区域的填充设置为 0。
Padding on the text fields give it extra space on the sides. Set the padding of inputs and textareas to 0.
问题是表单部分通常不会像普通 HTML 元素一样呈现,而且它们的样式总是有点随意。我会尝试避免像这样需要精确调整大小的情况,但如果不能,请像这样拆分选择器:
请注意,我在宽度上添加了 20 px (10 x 2) 以补偿填充。
The problem is that the form parts are generally not rendered like normal HTML elements, and styling them is always a bit hit-or-miss. I would attempt to avoid a case like this that requires exact sizing, but if you can't, then split the selectors like this:
Note that I added 20 px (10 x 2) to the width to compensate for padding.
我使用了这个仅 CSS 的解决方案,它适用于 IE、FF 和 Chrome。基本上,这个想法是手动强制输入元素的高度大于标准框的值。对文本和按钮执行此操作:
例子:
I've used this CSS-only solution which works in IE, FF and Chrome. Basically, the idea is to manually force the height of input elements to values larger than standard boxes. Do this for both text and button:
Example: