<html> <head> </head> <body> <input type="text" value="1" style="min-width:1px;" /> </body> </html>
I want a text input field with a dynamically changing width, so that the input field fluids around its contents. Every input has a built-in padding of
2em, that is the problem and second problem is that
min-width ain’t working on input at all.
If I set width more than it is needed than the whole program is messy, I need the width of 1px, more only if it’s needed.
It sounds like your expectation is that the style be applied dynamically to the width of the textbox based on the contents of the textbox. If so you will need some js to run on textbox contents changing, something like this:
<input id="txt" type="text" onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';">
Note: this solution only works when every character is exactly