8

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

2
  • Can you specify max-height property?
    – user6845426
    Commented Mar 12, 2017 at 15:51
  • When you write inside a textarea its height changes? Its the first time I hear about that feature... Commented Mar 12, 2017 at 16:02

2 Answers 2

22

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>

1
  • 1
    Thanks @vp_arth, this helped me, I have used em instead of %, it's fixed my problem and kept textarea responsive as well Commented Mar 12, 2017 at 16:39
3

first of all. make sure there is no style in your html conflict with you css .

that can cause same problem

  • for all textarea :

    textarea {
     resize: none;
    }
    
  • or

    textarea { 
     max-height: 100px;
    }
    

change "100" to what ever you want.

or try this in your textarea :

<textarea style="resize:none"></textarea>
1
  • Thanks @kakashi, appreciate your help I checked my html and css but I didn't see any conflict, I tried your solution but the textarea still changes. Commented Mar 12, 2017 at 16:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.