Dynamically Adjust HTML Text Input Width to Content

后端 未结 5 1838
夕颜
夕颜 2020-12-10 12:38

I can\'t quite find a clear answer on this, and excuse me if there is one I\'ve missed.

I want my text input widths to automatically adjust to the size of the conten

5条回答
  •  一个人的身影
    2020-12-10 13:10

    input.addEventListener('input', () => input.style.width = input.scrollWidth);
    

    Unfortunately this will only increase the size of the input. If you delete characters the size will not decrease. For some use cases this is perfectly fine.

提交回复
热议问题