Turn off textarea resizing
Asked Answered
T

8

129

I'm trying to turn off textarea resizing in my site; right now I'm using this method:

.textarea {
    clear:left;
    min-width: 267px;
    max-width: 267px;
    min-height:150px;
    max-height:150px;
}

I know that my method is not correct and I'm searching for a better one in JavaScript. I'm a beginner, so the best solution for me will be HTML5 or jQuery.

Tropism answered 9/7, 2012 at 19:17 Comment(0)
R
281

Try this CSS to disable resizing

The CSS to disable resizing for all textareas looks like this:

textarea {
    resize: none;
}

You could instead just assign it to a single textarea by name (where the textarea HTML is ):

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

Or by id (where the textarea HTML is ):

#foo {
    resize: none;
}

Taken from: http://www.electrictoolbox.com/disable-textarea-resizing-safari-chrome/

Radicand answered 9/7, 2012 at 19:21 Comment(1)
Instead of just linking to a solution, you should explain it a little here. A lot of other people looking at this question in the future won't be bothered to click a link for an answer. Add some detail here and I'll +1 your answer.Juliannejuliano
U
23

this will do your job

  textarea{
        resize:none;
    }

enter image description here

Unwashed answered 9/7, 2012 at 19:23 Comment(0)
T
9

CSS3 can solve this problem. Unfortunately it's only supported on 60% of used browsers nowadays.

For IE and iOS you can't turn off resizing but you can limit the textarea dimension by setting its width and height.

/* One can also turn on/off specific axis. Defaults to both on. */
textarea { resize:vertical; } /* none|horizontal|vertical|both */

See Demo

Testament answered 30/10, 2015 at 23:24 Comment(0)
B
6

This is works for me

<textarea
  type='text'
  style="resize: none"
>
Some text
</textarea>
Breechloader answered 23/10, 2019 at 5:20 Comment(0)
J
3

Just one extra option, if you want to revert the default behaviour for all textareas in the application, you could add the following to your CSS:

textarea:not([resize="true"]) {
  resize: none !important;
}

And do the following to enable where you want resizing:

<textarea resize="true"></textarea>

Have in mind this solution might not work in all browsers you may want to support. You can check the list of support for resize here: http://caniuse.com/#feat=css-resize

Juback answered 8/7, 2016 at 20:17 Comment(0)
H
1

As per the question, i have listed the answers in javascript

By Selecting TagName

document.getElementsByTagName('textarea')[0].style.resize = "none";

By Selecting Id

document.getElementById('textArea').style.resize = "none";
Hypnotherapy answered 6/12, 2017 at 7:5 Comment(0)
P
0
//CSS:
.textarea {
    resize: none;
    min-width: //-> Integer number of pixels
    min-height: //-> Integer number of pixels
    max-width: //-> min-width
    max-height: //-> min-height
}

above code works on most browsers

//HTML:
<textarea id='textarea' draggable='false'></textarea>

do both for it to work on the maximum number of browsers

Purgatorial answered 18/12, 2016 at 18:32 Comment(0)
E
-1

It can done easy by just using html draggable attribute

<textarea name="mytextarea" draggable="false"></textarea>

Default value is true.

Exiguous answered 21/7, 2015 at 5:23 Comment(1)
The question is about resizing the textarea, not drag and drop. So as expected, setting this attribute on a textarea doesn't do the trick in Chrome (at least).Gabrielson

© 2022 - 2024 — McMap. All rights reserved.