簡體   English   中英

為什么按鈕元素的高度與具有相同高度屬性的兄弟輸入元素的高度不匹配?

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

我有以下內容:

<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>

正如你在這個jsFiddle中看到的那樣 ,為什么按鈕元素1px比其他元素短? 在Chrome和Firefox中。

它與瀏覽器實現這些元素的盒子模型的方式有關。

divinput都使用content-box where-as button使用border-box

有關詳細信息,請參閱此處: http//www.quirksmode.org/css/box.html

您可以添加box-sizing: content-box; -moz-box-sizing: content-box; -ms-box-sizing: content-box;

到CSS強制它使用計算維度的內容框方法。

編輯 - 更多信息為什么Firefox使用IE框模型作為輸入元素?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM