Html – How to disable the resizable property of a textarea
csshtml
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?
Best Solution
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;
There are two other answers briefly mentioning flexbox; however, that was more than two years ago, and they don't provide any examples. The specification for flexbox has definitely settled now.
Note: Though CSS Flexible Boxes Layout specification is at the Candidate Recommendation stage, not all browsers have implemented it. WebKit implementation must be prefixed with -webkit-; Internet Explorer implements an old version of the spec, prefixed with -ms-; Opera 12.10 implements the latest version of the spec, unprefixed. See the compatibility table on each property for an up-to-date compatibility status.
With flexbox you can easily switch between any of your rows or columns either having fixed dimensions, content-sized dimensions or remaining-space dimensions. In my example I have set the header to snap to its content (as per the OPs question), I've added a footer to show how to add a fixed-height region and then set the content area to fill up the remaining space.
Of course, you don't have to set the width to 50%. Any width less than the containing <div> will work. The margin: 0 auto is what does the actual centering.
If you are targeting Internet Explorer 8 (and later), it might be better to have this instead:
#inner {
display: table;
margin: 0 auto;
}
It will make the inner element center horizontally and it works without setting a specific width.
Best Solution
The following CSS rule disables resizing behavior for
textarea
elements:To disable it for some (but not all)
textarea
s, there are a couple of options.You can use
class
attribute in your tag(<textarea class="textarea1">
):To disable a specific
textarea
with thename
attribute set tofoo
(i.e.,<textarea name="foo"></textarea>
):Or, using an
id
attribute (i.e.,<textarea id="foo"></textarea>
):The W3C page lists possible values for resizing restrictions: none, both, horizontal, vertical, and inherit:
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.