0

How can I shrink (and stretch if possible) a <input type="text" /> based on the input value? I mean, how to reduce the inner "margin" of the input element when the input is too short?

https://jsfiddle.net/hstutyex/3/

My real project uses datepicker and the format of date is noticeably shorter than the input, which causes a layout problem.

JS-less solution would be appreciated but if it's impossible using JS (and jQuery) is okay.

akai
  • 2,294
  • 3
  • 20
  • 44

1 Answers1

0

use onKeyPress event to do that, below is an example :

<input type="text" 
       onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';">
Abdennour TOUMI
  • 76,783
  • 33
  • 229
  • 231