Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fix textarea height size

Tags:

html

css

I hope you can help me, I'm junior in html/css

I have a textarea with known height in percentage value inside a div of unknown height, when I'm trying to write inside this textarea, it's height get changed.

my question is, how to fix textarea height when trying to write inside it by percentage value

I know that I need to fix div height first by specify its height using px or % in order to make textarea height fix.

I tried these attributes but no luck

resize: none;
display:block;

Please note that the div height is changeable and it works as container for multiple textarea so that I can't add a specific height for it,

BTW, this issue is happening on all browsers

Please help

like image 638
optimistic-usr Avatar asked Mar 12 '17 15:03

optimistic-usr


People also ask

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 restrict textarea size?

In some cases, there is a need of putting a limit on the size of characters that can be typed in a textarea. So in that case, we can use maxlength attribute to control the number of characters entered in a textarea.

How do I resize textarea in HTML?

You can resize a textarea by clicking on the bottom right corner of the textarea and dragging the mouse.

How do you 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.


1 Answers

CSS rule resize: none; does this job.

You can also set your textarea height in rows count with rows attribute.

textarea {
  resize: none;
}
textarea.ta10em {
  height: 10em;
}
<div>
  <textarea rows=3>Some text
Second line
Third line</textarea>
</div>
<div>
  <textarea class="ta10em">Some text
Second line</textarea>
</div>
like image 151
vp_arth Avatar answered Oct 14 '22 05:10

vp_arth