<hr>:主题分隔(水平线)元素

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

<hr> HTML 元素代表段落级元素之间的主题分隔:例如,故事中的场景转换,或者一个部分内的话题转移。

试一试

<p>§1: The first rule of Fight Club is: You do not talk about Fight Club.</p>

<hr />

<p>§2: The second rule of Fight Club is: Always bring cupcakes.</p>
hr {
  border: none;
  border-top: 3px double #333333;
  color: #333333;
  overflow: visible;
  text-align: center;
  height: 5px;
}

hr::after {
  background: white;
  content: "§";
  padding: 0 4px;
  position: relative;
  top: -13px;
}

历史上,这被呈现为一条水平线或分隔线。虽然在视觉浏览器中它仍然可以显示为一条水平线,但该元素现在是根据语义而不是表现来定义的,所以如果你想绘制一条水平线,你应该使用合适的 CSS 来实现。

属性

此元素的属性包括全局属性

align 已弃用 非标准

设置页面上分隔线的对齐方式。如果未指定值,则默认值为 left

color 已弃用 非标准

通过颜色名称或十六进制值设置分隔线的颜色。

noshade 已弃用 非标准

设置分隔线不显示阴影。

size 已弃用 非标准

设置分隔线的高度(以像素为单位)。

width 已弃用 非标准

通过像素值或百分比值设置页面上分隔线的长度。

示例

HTML

html
<p>
  This is the first paragraph of text. This is the first paragraph of text. This
  is the first paragraph of text. This is the first paragraph of text.
</p>

<hr />

<p>
  This is the second paragraph of text. This is the second paragraph of text.
  This is the second paragraph of text. This is the second paragraph of text.
</p>

结果

技术摘要

内容类别 流内容.
允许内容 无;它是一个空元素
标签省略 必须有起始标签,且不能有结束标签。
允许父级
隐式 ARIA 角色 separator
允许的 ARIA 角色 presentationnone
DOM 接口 HTMLHRElement

规范

规范
HTML
# the-hr-element

浏览器兼容性

另见