Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is possible to expand a textarea only with CSS?

Tags:

html

css

I have a textarea with 200px of height, but when I pass that 200px with text I want to have the textarea expanded instead of keeping the 200px of height with a scroll bar.

It is possible to do that only with CSS?

like image 845
swayziak Avatar asked Apr 07 '13 18:04

swayziak


People also ask

How do I expand textarea automatically?

It can be achieved by using JavaScript and jQuery. Method 1: Using JavaScript: To change the height, a new function is created which changes the style property of the textarea. The height of the textarea is first set to auto. This value makes the browser set the height of an element automatically.

How make textarea responsive CSS?

Try textarea {max-width:95%;} - it will always fit your display. Show activity on this post. I set the number of columns to slightly greater that the width of the div on a large screen and as the screen gets smaller it acts responsive to the screen size.

How can I change textarea size?

The size of a text area is specified by the cols and rows attributes (or with CSS). The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the text area will be submitted). The id attribute is needed to associate the text area with a label.


2 Answers

Instead of textarea , you can use div with contentEditable attribute:

div {    display: inline-block;    border: solid 1px #000;    min-height: 200px;    width: 300px;  }
<div contentEditable="true"></div>

DEMO

like image 79
Engineer Avatar answered Sep 19 '22 07:09

Engineer


It is possible to make a textarea expandable by the user, using just CSS. In fact, in some modern browsers, such expandability is even the browser default. You can explicitly ask for it:

textarea { resize: both; } 

Browser support is growing but is still limited.

There is typically just a small hint about resizability: a resize handle in the lower right corner. And I’m afraid most users won’t understand this hint.

You cannot make a textarea expand automatically by content using just CSS.

like image 36
Jukka K. Korpela Avatar answered Sep 21 '22 07:09

Jukka K. Korpela