I was searching for solutions to this very problem, or at least I think it's the same issue. I solved it too. Let me explain.
Depending on the browser, I had the textbox get too long or too short, but also noticed it sometimes did fit as intended. I used @meadia
constructs to scale the UI depending on client viewport size and noticed it fit perfectly when the scaling was 100%, only. This led me to a different solution, or rather, pointed me to a different problem.
I am not sure this is the case for all browsers, but I could solve it by adding a few simple settings in the start of my CSS file (the CSS reset part), adding the following:
/***************************************************/
/* Hack to make input[type='text'] fit width of
parent element */
input {font-size: 1em;} /* omitting [type=... deliberately */
textarea {font-size: 1em;}
/***************************************************/
/* Media scaling */
* {margin: 0; border: 0; padding: 0;}
html {min-width: 300px;}
body {font-size: 80%;} /* Default */
@media (min-width: 400px) {body {font-size: 80%;}}
@media (min-width: 600px) {body {font-size: 90%;}}
@media (min-width: 900px) {body {font-size: 95%;}}
@media (min-width: 1300px) {body {font-size: 100%;}}
@media (min-width: 1800px) {body {font-size: 110%;}}
@media (min-width: 2400px) {body {font-size: 120%;}}
Apparently using a CSS reset that specifies font size before scaling fixes the problem. I think this actually makes sense too. The thing easily forgotten is that elements are not always inheriting correctly from the body, in this case text type inputs (and also textareas).
Make sure you are setting the width: 100%;
style for the textbox in the TD or DIV, and that you are also setting box-sizing: border-box;
. Should make it work.
Hope this helps.