Textarea调整大小 [英] Textarea resize

查看:219
本文介绍了Textarea调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用textarea来显示一些文本。问题是,如果我放置4-5行文本,将出现一个滚动条。如何使用CSS / HTML,以便textarea将与其内容一样大(无滚动条)。

I need to use a textarea to show some text. The problem is that if I place 4-5 rows of text a scrollbar will appear. How can I use CSS/HTML so that the textarea will be as large as it's content (no scrollbar).


  • textarea不需要改变它的大小动态,我使用它只显示一个文本(我也可以使用禁用textarea)

  • the textarea doesn't need to change it's size dynamicaly, I use it only to show a text (I could also use a disabled textarea)

我想textarea

I want the textarea to stretch only verticaly.

如果您想知道:

我使用textarea来自数据库的一些文本,所以当textarea(与其中的文本)被创建时,它应该显示整个文本,没有滚动条。

If you want to know:
I use the textarea to show some text from a database, so when the textarea (with the text in it) is created, it should show the whole text at once with no scrollbars.

推荐答案

我恐怕你必须使用javascript来设置textarea的高度。您可以使用 scrollHeight 属性来确定总高度。

I´m afraid you´ll have to resort to javascript to set the height of your textarea. You can use the scrollHeight property to determine the total height.

也可以使用 div 并将 div 的样式设置为textarea。 div 将自动增长,因为它是一个禁用的textarea无论如何,你不需要它是一个textarea。

Alternatively you could just use a div and style the div to look like a textarea. The div will grow automatically and as it´s a disabled textarea anyway, you don´t really need it to be a textarea.

这篇关于Textarea调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆