HTML rows 属性用于指定 textarea 的行高度。
<textarea> 元素是一个多行纯文本编辑控件,当您希望用户输入大量自由格式的文本时,该控件非常有用。
文本区域的大小也可以通过 CSS height 和 width 属性来指定。
语法
<textarea rows="5" >
其中 rows=“5” 指定文本区域用于编写段落或其他任何内容的 5 行。
适用对象
下面列出的元素允许使用 HTML rows 属性。
元素 | 描述 |
---|---|
<textarea> | HTML <textarea> 标签用于表示多行纯文本编辑控件。 |
HTML rows 属性的示例
以下示例将说明 HTML rows 属性,我们应该在何处以及如何使用此属性!
指定高度、宽度、文本区域
输出窗口显示具有三个可见行的 textarea。
<!DOCTYPE html>
<html>
<head>
<title>HTML rows Attribute</title>
</head>
<body>
<h2>HTML rows Attribute</h2>
<textarea rows="3">
The only real mistake is the one
from which we learn nothing.
</textarea>
<p>
This textarea has 3 visible rows.
</p>
<p>
You can change that by changing
the value of the "rows" attribute.
</p>
</body>
</html>
使用内部 CSS 覆盖 rows 属性
输出窗口显示 textarea,其尺寸在 style 标签中给出。这将覆盖 textarea 中提到的 rows 属性。
<!DOCTYPE html>
<html>
<head>
<title>HTML rows Attribute</title>
<style>
textarea {
height: 8em;
width: 15em;
}
</style>
</head>
<body>
<h2>HTML rows Attribute</h2>
<textarea rows=2>
The only real mistake is the one
from which we learn nothing.
</textarea>
<p>
You can change height of the text area by
changing the value of the height in the CSS.
</p>
</body>
</html>
支持的浏览器
浏览器 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
是否支持 | Yes | Yes | Yes | Yes | Yes |