textarea: can you make it same height as content text?

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4434
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

textarea: can you make it same height as content text?

Post by simonmlewis »

We have a textarea per row, showing a description. But we don't want to have to keep resizing the box.
I have a script that will resize a box when you Add a product, but we want the textarea to be the height of the text within it.

I thought "height: auto" would work, but it doesn't.

Any ideas?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: textarea: can you make it same height as content text?

Post by Celauran »

Something like this? http://jsfiddle.net/zwcvd5ae/
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: textarea: can you make it same height as content text?

Post by pickle »

About the only way I know of is to use Javascript. Create an invisible <div> off screen that is the same width as the textarea will be, then insert the content into that div. Then, find the height of that div and set the height of the textarea to the same.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply