HTML - rows 屬性



HTML rows 屬性用於指定文字區域的高度(以行數計)。

<textarea> 元素是一個多行純文字編輯控制元件,當您希望使用者輸入大量自由格式文字時很有用。

文字區域的大小也可以透過 CSS 的 height 和 width 屬性來指定。

語法

<textarea rows="5" >

其中 rows="5" 指定文字區域佔用 5 行來編寫段落或其他內容。

應用於

以下列出的元素允許使用 HTML rows 屬性。

元素 描述
<textarea> HTML <textarea> 標籤用於表示多行純文字編輯控制元件。

HTML rows 屬性示例

以下示例將說明 HTML rows 屬性,以及我們應該在哪裡以及如何使用此屬性!

指定高度寬度文字區域

輸出視窗顯示具有三行可見行的文字區域。

<!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 屬性

輸出視窗顯示具有 style 標籤中給定尺寸的文字區域。這將覆蓋文字區域中提到的 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>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
rows
html_attributes_reference.htm
廣告

© . All rights reserved.