Given a <select>
and an <input>
element, both specified to be 200px wide:
<!doctype html>
<body>
<select style="width: 200px"></select><br/>
<input style="width: 200px" type="text">
</body>
<html>
One ends up wider1,2,3, 4 than the other:
What is the reason for this?
If someone can give the reason, perhaps the solution would be obvious, and not a hack&pray.
Layout
The applied layout is perfectly reasonable:
Update 1: While i was writing this question Chrome updated itself from 17 to 19.
Update 2: Changing padding in the <input>
from 1 to zero:
<!doctype html>
<body>
<select style="width: 200px"></select><br/>
<input style="width: 200px; padding: 0" type="text">
</body>
<html>
doesn't make the <input>
200px wide (i.e. doesn't fix it).
Update 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>
Does not solve the problem:
Also, i am less interested in a solution than an explanation.
Footnotes
- 1,2,3 Chrome
1719, Firefox, Internet Explorer 9 - 4 on Windows 7 64-bit
Bonus Reading
- How to make <option> wider than <select> in IE6? (i don't want the option to be wider than the select, i'm not using IE6)
- How to show extended option in select list? (width of dropdown matches width of control)
- HTML input element wider than Containing Div (no containing
<div>
here) - How to line up HTML input elements?