【发布时间】:2012-06-22 22:53:36
【问题描述】:
给定一个 <select> 和一个 <input> 元素,都指定为 200px 宽:
<!doctype html>
<body>
<select style="width: 200px"></select><br/>
<input style="width: 200px" type="text">
</body>
<html>
一个比另一个宽1,2,3,4:
这是什么原因?
如果有人可以给出原因,也许解决方案会很明显,而不是a hack&pray。
布局
应用的布局非常合理:
更新 1:当我写这个问题时Chrome updated itself from 17 to 19。
更新 2: 将 <input> 中的填充从 1 更改为 0:
<!doctype html>
<body>
<select style="width: 200px"></select><br/>
<input style="width: 200px; padding: 0" type="text">
</body>
<html>
不会使<input> 200px 变宽(即不修复它)。
更新 3: Applying a CSS reset:
<!doctype html>
<head>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
</style>
<body>
<select style="width: 200px"></select><br/>
<input style="width: 200px; padding: 0" type="text">
</body>
<html>
没有解决问题:
另外,我对解决方案的兴趣不如解释。
脚注
-
1,2,3 Chrome
1719, Firefox, Internet Explorer 9 - 4 在 Windows 7 64 位上
阅读奖励
- How to make <option> wider than <select> in IE6?(我不希望选项比选择更宽,我没有使用 IE6)
- How to show extended option in select list?(下拉菜单的宽度与控件的宽度匹配)
-
HTML input element wider than Containing Div(此处不包含
<div>) - How to line up HTML input elements?
【问题讨论】:
-
计算的样式显示什么?有什么填充物吗?
-
使用 CSS 重置并省去一些痛苦。
-
为所有设置相同的边距/填充
-
选择元素使用
box-sizing: border-box。
标签: html css html-select html-input