Reputation: 625
Consider a code:
<div style="width: 10em; float: left; padding: 0; margin: 0">
<input type="text" style="width: 10em"/>
</div>
In fact, the text field does not occupy the entire parent DIV, as one would expect. Why? Thanks in advance for your answers.
Upvotes: 2
Views: 408
Reputation: 2166
the answer is font-sizes.
em is a measurement of 'size relative to the current font-size'.
since the default font-size of an input element is smaller than a div (due to browser defaults) the 10em equates to a different width.
you can easily fix this by using '%' unit:
<input type="text" style="width:100%"/>
Upvotes: 3
Reputation: 38318
Try using a 100% width instead of an em
width:
<div style="width: 10em; float: left; padding: 0; margin: 0">
<input type="text" style="width: 100%"/>
</div>
Note that the text field will still have a padding and border - so a width of 100% will overflow the containing div.
Upvotes: 1
Reputation: 2439
<!DOCTYPE html>
<html>
<head>
<title> problem </title>
</head>
<body>
<div style="width: 10em; float: left; padding: 0; margin: 0;background-color:red;">
<input type="text" style="width: 100%; padding:0; margin:0"/>
</div>
</body>
</html>
Upvotes: 0