Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable the resizable property of a textarea?

Tags:

html

css

I want to disable the resizable property of a textarea.

Currently, I can resize a textarea by clicking on the bottom right corner of the textarea and dragging the mouse. How can I disable this?

Enter image description here

like image 562
user549757 Avatar asked Mar 08 '11 16:03

user549757


People also ask

How do I restrict textarea size?

You can set the size of a text area using the cols and rows attributes. To limit the number of characters entered in a textarea, use the maxlength attribute. The value if the attribute is in number. Specifies that on page load the text area should automatically get focus.

Can you disable a textarea?

In order to disable a textarea (or any other input element), you can: In HTML, you can write: <textarea id='mytextarea' disabled></textarea> From jQuery, you can: $("#mytextarea"). attr("disabled","disabled");

How do I set the fixed size textarea in HTML?

A text area can hold an unlimited number of characters, and the text renders in a fixed-width font (usually Courier). The size of a text area is specified by the <cols> and <rows> attributes (or with CSS).


2 Answers

The following CSS rule disables resizing behavior for textarea elements:

textarea {   resize: none; } 

To disable it for some (but not all) textareas, there are a couple of options.

You can use class attribute in your tag(<textarea class="textarea1">):

.textarea1 {   resize: none; } 

To disable a specific textarea with the name attribute set to foo (i.e., <textarea name="foo"></textarea>):

textarea[name=foo] {   resize: none; } 

Or, using an id attribute (i.e., <textarea id="foo"></textarea>):

#foo {   resize: none; } 

The W3C page lists possible values for resizing restrictions: none, both, horizontal, vertical, and inherit:

textarea {   resize: vertical; /* user can resize vertically, but width is fixed */ } 

Review a decent compatibility page to see what browsers currently support this feature. As Jon Hulka has commented, the dimensions can be further restrained in CSS using max-width, max-height, min-width, and min-height.

Super important to know:

This property does nothing unless the overflow property is something other than visible, which is the default for most elements. So generally to use this, you'll have to set something like overflow: scroll;

Quote by Sara Cope, http://css-tricks.com/almanac/properties/r/resize/

like image 59
Donut Avatar answered Oct 04 '22 10:10

Donut


In CSS ...

textarea {     resize: none; } 
like image 22
Jeff Parker Avatar answered Oct 04 '22 10:10

Jeff Parker