I have div of fixed width containing only input text box and width of that input is set to 100%. I expect it to fill the div but instead it is slightly longer.
Demonstration code:
HTML:
<div class="container">
<input class="content" id="Text1" type="text" />
</div>
CSS:
.container
{
width: 300px;
height: 30px;
border: thin solid red;
}
.content
{
width: 100%;
}
Result (Firefox):

This happens also in IE 8, Chrome, Safari… The overflow width seems to vary in different browsers.
How do I make the content to exactly fill the width of the div?
box-sizing: border-boxis a quick, easy way to fix it:This will work in all modern browsers, and IE8+.
Here’s a demo: http://jsfiddle.net/thirtydot/QkmSk/301/
See here for an icky IE7 compatible method.