admin管理员组文章数量:1415095
I have created a textarea that outputs custom text. I want to have it scale to fit the text if there is too much, and not have to scroll (unless the textarea is a certain height). I also do not want to be able to manually scale the textarea. How would I go about doing this? Thank you in advance.
I have created a textarea that outputs custom text. I want to have it scale to fit the text if there is too much, and not have to scroll (unless the textarea is a certain height). I also do not want to be able to manually scale the textarea. How would I go about doing this? Thank you in advance.
Share Improve this question asked Apr 8, 2015 at 6:59 Dr. OwningDr. Owning 1733 silver badges14 bronze badges 2- 1 HTML <textarea> Tag – ozil Commented Apr 8, 2015 at 7:04
- do you also want textarea of fixed width? – nehal gala Commented Apr 8, 2015 at 7:10
2 Answers
Reset to default 5You might want to take a look at this. Seems to be a solution for you problem. There is a jsfiddle in the accepted answer that shows the result.
To take out the most important function see below. It sets the textareas height equal to its scrollHeight.
function resize () {
var text = document.getElementById('text');
text.style.height = 'auto';
text.style.height = text.scrollHeight+'px';
}
You have do this via CSS
textarea
{
overflow : auto;
}
本文标签: javascriptMake textarea scale vertically to fit textStack Overflow
版权声明:本文标题:javascript - Make textarea scale vertically to fit text? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745174305a2646162.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论