Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want my textarea to have a fixed width [duplicate]

Tags:

I have seen it on some sites where the textarea input can by drawn only downward but not to sideways.

<textarea cols="10" rows="5" charswidth="23" name="text_body"></textarea>
I have tried those but the width is still extendable. Please how can I do this?
like image 469
Stephinext Avatar asked Apr 24 '16 15:04

Stephinext


People also ask

How can I fix the width of my textarea?

To prevent a text field from being resized, you can use the CSS resize property with its "none" value. After it you can use the height and width properties to define a fixed height and width for your <textarea> element.

How do I stop textarea from resizing?

A simple way to ensure that the control is not resizable is to add an explicit style="resize: none;" attribute on the textarea element using the HTML Form Element Attributes property.

How do I automatically resize 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.


2 Answers

textarea {    resize: vertical;  }
<textarea cols="10" rows="5" charswidth="23" name="text_body"></textarea>

JSFiddle Demo

like image 55
Keiwan Avatar answered Sep 19 '22 00:09

Keiwan


This can be achieved via CSS.

    <textarea cols="10" rows="5" charswidth="23" name="text_body" style="resize:vertical"></textarea>
like image 31
chatuur Avatar answered Sep 22 '22 00:09

chatuur