html5的文本大纲的作用,使用 HTML 章节与大纲

因为HTML5分节元素并不强制性定义大纲,为了与现有的占主导地位的HTML4保持兼容,有个方式来定义节段而不需要分节元素。这种方式就是隐式分节。

HTML标题元素 (

(en-US) 到

(en-US)) 定义了一个新的,隐式的节段,当其不是父节段第一个标题时。这种隐式放置节段的方式通过在父节点中与之前标题的相对级别来定义。如果比之前的标题级别更低,那么在节段里开始新的隐式子节段。如代码所示:

Forest elephants

In this section, we discuss the lesser known forest elephants.

...this section continues...

Habitat

Forest elephants do not live in trees but among them.

...this subsection continues...

形成如下的大纲:

1. Forest elephants

1.1 Habitat (implicitly defined by the h3 element)

如果与前面标题的级别相同,那么闭合前面的节段(可能是显式标记的节段!)并开始新的同一级别的隐式节段:

Forest elephants

In this section, we discuss the lesser known forest elephants.

...this section continues...

Mongolian gerbils

Mongolian gerbils are cute little mammals.

...this section continues...

形成如下的大纲:

1. Forest elephants

2. Mongolian gerbils (implicitly defined by the h1 element, which closed the previous section at the same time)

如果比之前标题的级别更高,那么关闭之前的节段并开始新的这个更高级别的隐式节段:

Mammals

Whales

In this section, we discuss the swimming whales.

...this section continues...

Forest elephants

In this section, we discuss the lesser known forest elephants.

...this section continues...

Mongolian gerbils

Hordes of gerbils have spread their range far beyond Mongolia.

...this subsection continues...

Reptiles

Reptiles are animals with cold blood.

...this subsection continues...

形成如下的大纲:

1. Mammals

1.1 Whales (implicitly defined by the h2 element)

1.2 Forest elephants (explicitly defined by the section element)

1.3 Mongolian gerbils (implicitly defined by the h3 element, which closes the previous section at the same time)

2. Reptiles (implicitly defined by the h2 element, which closes the previous section at the same time)

这并不是一眼就可以通过标题标记就可以看出来的大纲。为了使标记容易理解,用显式的标记开始和闭合节段以及匹配标题等级与期望的嵌套节段等级。然而,HTML5规范并不需要这样。如果你发现浏览器以不期望的方式渲染文档,检查是否有隐式的节段没有闭合。

作为经验法则,标题级别应该与节段嵌套级别相匹配,但为了方便节段在多个文档中的重用,也存在例外的情况。例如,一个节段可能会存储在内容管理系统中并在运行时组装为完整的文档。在这种情况下,好的实践便是使用

(en-US)作为可重用部分的最高标题级别。可重用节段的嵌套级别应该取决于将使用该节段的文档的节段层级。显式节段标记仍然在这种情况下有用处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值