在 HTML 中新增水平線


HTML 中的<hr>標籤是水平線,用於定義 HTML 頁面中的主題分隔符。它通常用於顯示水平線以分隔內容或更改 HTML 頁面中內容的顯示方式。它在 HTML 中只包含開始標籤。

語法

下面顯示了在 HTML 中使用<hr>標籤的方法:

<hr>………

HTML <hr>標籤支援以下附加屬性:

屬性

描述

align

left center right

指定水平線的對齊方式。

noshade

Noshade

移除大多數瀏覽器顯示的常用陰影效果。

size

畫素或 %

指定水平線的高度。

width

畫素或 %

指定水平線的寬度。

示例

以下示例演示了在 HTML 中使用<hr>標籤:

<!DOCTYPE html>
<html>
<head>
   <title>HTML hr Tag</title>
</head>
<body>
   <p>This text will be followed by a horizontal line</p>
   <hr>
   <p>Another horizontal line</p>
   <hr>
</body>
</html>

示例

現在,讓我們透過為<hr>標籤的屬性賦值來看一個例子:

<!DOCTYPE html>
<html>
<head>
   <title>HTML hr Tag</title>
</head>
<body>
   <p>This text will be followed by a horizontal line</p>
   <hr style="width:30%;text-align:left;margin-left:0">
   <p>Continue another sentence here....</p>
</body>
</html>

示例

以下是 CSS 中無陰影<hr>元素的示例:

<!DOCTYPE html>
<html>
<body>
   <p>Demonstrating noshaded horizontal line:</p>
   <hr>
   <p>Applying styling sheet</p>
   <hr style="height:2px;border-width:0;color:grey;background-color:red">
</body>
</html>

示例

以下示例演示了使用 CSS 設定<hr>元素的高度:

<!DOCTYPE html>
<html>
<body>
   <p>Height of horizontal line:</p>
   <hr>
   <p>A horizontal line with a height of 50 pixels:</p>
   <hr style="height:50px">
</body>
</html>

示例

在以下示例中,我們使用 CSS 屬性更改<hr>元素的寬度:

<!DOCTYPE html>
<html>
<body>
   <p>Normal horizontal line:</p>
   <hr>
   <p>A horizontal line with a width of 30 %:</p>
   <hr style="width:30%">
</body>
</html>

更新於:2023年10月10日

572 次瀏覽

啟動你的職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.