Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textarea height: 100%

Tags:

html

css

Here's my fiddle: http://jsfiddle.net/e6kCH/15/

It may sound stupid, but I can't find a way to make the text area height equal to 100%. It works for the width, but not for height.

I want the text area to resize depending of the window size...like it works in my fiddle for the width...

Any ideas?

like image 517
larin555 Avatar asked Jun 18 '12 19:06

larin555


People also ask

How to make textarea 100%?

The idea is to create a div with the class name “wrapper”. Inside that <div> element, we create a text area with a certain number of columns and rows. In this case, it is 30 and 15 respectively. After that, we set the width property to 100% to make a textarea width 100%.

How do I Auto Expand textarea?

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 do I increase the width of a textarea in HTML?

You need to define width of the div containing the textarea and when you declare textarea , you can then set . main > textarea to have width: inherit . Note: .


1 Answers

Height of an element is relative to its parent. Thus, if you want to make expand your element into the whole height of the viewport, you need to apply your CSS to html and body as well (the parent elements):

html, body {     height: 100%; }  #textbox {     width: 100%;     height: 100%; } 

Alternative solution with CSS3: If you can use CSS3, you can use Viewport percentage units and directly scale your textbox to 100 % height (and 100% width) of the viewport (jsfiddle here)

body {     margin: 0; } #textbox {     width: 100vw;     height: 100vh; } 
like image 106
jsalonen Avatar answered Sep 24 '22 10:09

jsalonen