简体   繁体   English

为什么按钮元素的高度与具有相同高度属性的兄弟输入元素的高度不匹配?

[英]Why does a button element's height not match that of a sibling input element with same height properties?

I have the following: 我有以下内容:

<div    style="border:solid 1px gray; height:22px; line-height:22px; display:inline-block;">Div</div>
<input  style="border:solid 1px gray; height:22px; line-height:22px; vertical-align:top;" type="text">
<button style="border:solid 1px gray; height:22px; line-height:22px; vertical-align:top;">Button</button>

As you can see in this jsFiddle , Why is the button element 1px shorter than the rest? 正如你在这个jsFiddle中看到的那样 ,为什么按钮元素1px比其他元素短? in Chrome and firefox. 在Chrome和Firefox中。

It has to do with the way the browser implements the box model for those elements. 它与浏览器实现这些元素的盒子模型的方式有关。

div and input both use the content-box where-as button uses border-box divinput都使用content-box where-as button使用border-box

See here for more info: http://www.quirksmode.org/css/box.html 有关详细信息,请参阅此处: http//www.quirksmode.org/css/box.html

You can add box-sizing: content-box; 您可以添加box-sizing: content-box; , -moz-box-sizing: content-box; -moz-box-sizing: content-box; , -ms-box-sizing: content-box; -ms-box-sizing: content-box;

to the CSS to force it to use the content-box method of calculating dimensions. 到CSS强制它使用计算维度的内容框方法。

Edit--More Info : Why does Firefox use the IE box model for input elements? 编辑 - 更多信息为什么Firefox使用IE框模型作为输入元素?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM