Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: one row of <textarea> is of how much height?

I want to know the height of one row of <textarea>. I want to know that because I want to do some calculations.

Do we know it or do we have to do some scripting?

like image 797
Mohammad Areeb Siddiqui Avatar asked Jul 04 '13 17:07

Mohammad Areeb Siddiqui


People also ask

What is rows in textarea?

The rows attribute specifies the visible height of a text area, in lines. Note: The size of a textarea can also be specified by the CSS height and width properties.

What is rows and cols in textarea?

rows/cols is based on the character size of the user. So if you have a css-defined width/height that cannot be divided by the pixles of a character in the textarea, there is going to be that much whitepsace left over vertically and horizontally.

How do I change the width and height of a textarea in HTML?

The cols attribute specifies the visible width of a text area. Tip: The size of a text area can also be set by the CSS height and width properties.


3 Answers

The height of a row is set by line-height.

For example:

<textarea rows="1">hello world</textarea>

If you set the following:

textarea { line-height: 1; font-size: 12px; border: none; margin: 0; padding: 0; }

By inspecting the textarea element you'll find out that it has a height of 12px.

like image 183
Ruben Kislaki Avatar answered Sep 20 '22 20:09

Ruben Kislaki


Basically it is the same as whatever the line-height is set to. You can either set it explicitly, or figure out what it is set to, and go from there.

Here is an example

like image 42
gotohales Avatar answered Sep 23 '22 20:09

gotohales


You could also determine the value of line-height (or any style) by using currentStyle or getComputedStyle, as per this answer for getting the line-height of a div:

https://stackoverflow.com/a/4392968/142714

And if you have jQuery you can use .css(), which abstracts the above (there are browser differences to consider).

like image 37
Darren Shewry Avatar answered Sep 23 '22 20:09

Darren Shewry