html - 一行 textarea 的高度是多少?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17475652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:47:32  来源:igfitidea点击:

html - One row of textarea is of how much height?

htmlheighttextarearowrow-height

提问by Mohammad Areeb Siddiqui

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?

我想知道一行 textarea 的高度。我想知道,因为我想做一些计算。我们知道它还是我们必须编写一些脚本?

回答by Ruben Kislaki

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

行的高度由 设置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.

通过检查 textarea 元素,您会发现它的高度为 12px。

回答by gotohales

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

基本上它与line-height设置的任何内容相同。您可以明确地设置它,或者弄清楚它的设置,然后从那里开始。

Here is an example

这是一个例子

回答by a darren

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

您还可以line-height使用currentStyleor来确定(或任何样式)的值getComputedStyle,根据这个获取 div 行高的答案:

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

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).

如果您有 jQuery,则可以使用.css(),它抽象了上述内容(需要考虑浏览器差异)。