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).
-
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)
-
I want the textarea to stretch only verticaly.
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.
I´m afraid you´ll have to resort to javascript to set the height of your textarea. You can use the
scrollHeightproperty to determine the total height.Alternatively you could just use a
divand style thedivto look like a textarea. Thedivwill grow automatically and as it´s a disabled textarea anyway, you don´t really need it to be a textarea.