使用HTML 5大纲(4)
“Vital caveat about the information above”(以上信息是重要警告),指的是整个文章,即介绍性的<h1>以下的所有内容;还是说它只是指打头的<h2>(“Fan Club uniforms”)以下的信息?在HTML 4中,该段落会是<h2>下面的内容,要从语义上改变这点很不容易。在HTML 5中,<section>元素可以使其含义明确(这也是作为Web开发者的我们使用单词“语义”时所表示的真正的意思):
广州网站建设,网站建设,广州网页设计,广州网站设计
- <article>
- <h1>Rules for Munchkins</h1>
- <section>
- <h2>Yellow Brick Road</h2>
- <p>It is vital that Dorothy follows it-so no selling
- bricks as "souvenirs"</p>
- </section>
- <section>
- <h2>Fan Club uniforms</h2>
- <p>All Munchkins are obliged to wear their "I'm a friend
- of Dorothy!" t-shirt when representing the club</p>
- </section>
- <p><strong>Vital caveat about the information above:
- does not apply on the first Thursday of the month.
- </strong></p>
- </article>
图2.10形象地说明了这一点。
![]() |
- <article>
- ...
- <section>
- <h2>Fan Club uniforms</h2>
- <p>All Munchkins are obliged to wear their "I'm a friend
- of Dorothy!" t-shirt when representing the club</p>
- <p><strong>Vital caveat about the information above:
- does not apply on the first Thursday of the month
- </strong></p>
- </section>
- </article>
它明确地只是引用该节,如图2.11所示。
广州网站建设,网站建设,广州网页设计,广州网站设计
![]() |
使用嵌套的article元素,无法像这样正确地划分这篇文章,因为它们不是独立的、离散的实体。
现在我们看到了可以让<article>位于<article>之中,让<section>位于<section>之中。但是也可以让<article>位于<section>之中。这究竟是什么呢?
位于<section>中的<article>
假想你的内容区域划分为两个部分,一部分是关于骆驼的文章,其他是关于根茎类蔬菜的文章。这是我喜欢的内容。
你不想分别标记骆驼的文章和根茎类蔬菜的文章,但是你想要表现出它们是不同的话题。当然由于它们是不同的话题,你希望它们位于不同的栏中,或者你将使用CSS和JavaScript来制作一个标签页界面。
在HTML 4中,你将使用无含义的朋友<div>。在HTML 5中,将使用<section>,它像<article>一样,调用HTML 5大纲算法(而<div>则不会,因为它没有特殊的结构化含义)。
- <section>
- <h1>Articles about llamas</h1>
- <article>
- <h2>The daily llama: buddhism and South American camelids
- </h2>
- <p>blah blah</p>
- </article>
- <article>
- <h2>Shh! Do not alarm a llama</h2>
- <p>blah blah</p>
- </article>
- </section>
- <section>
- <h1>Articles about root vegetables</h1>
- <article>
- <h2>Carrots: the orange miracle</h2>
- <p>blah blah</p>
- </article>
- <article>
- <h2>Eat more Swedes (the vegetables, not the people)</h2>
- <p>blah blah</p>
- </article>
- </section>





