TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
根据W3C的最新定义规范: section元素标签用来表现普通的文档内容或应用区块。一个section通常由内容及其标题组成...但section元素标签并非一个普通的容器元素;当一个容器需要被直接定义样式或通过脚本定义行为时,推荐使用div元素而非section。 下面的代码展示了一个最简单并且典型的section:
<section>
<h1>Any level of heading</h1>
rest of the content
</section>[/code]
通常不推荐为那些没有标题的内容使用<section>;我们可以使用HTML5轮廓工具来检查我们的页面中是否有不包含标题部分的<section>容器。
下面的
范例来自W3C官方;这一篇关于苹果的短文,其中包括两个简短的 section:
<article>
<hgroup>
<h1>Apples</h1>
<h2>Tasty, delicious fruit!</h2>
</hgroup>
<p>The apple is the pomaceous fruit of the apple tree.</p>
<section>
<h1>Red Delicious</h1>
<p>These bright red apples are the most common found in many supermarkets.</p>
</section>
<section>
<h1>Granny Smith</h1>
<p>These juicy, green apples make a great filling for apple pies.</p>
</section>
</article>[/code]
我们可以看到,虽然文章有正式的h1与h2,但是在<section>中,仍然可以为这个内容部分使用h1来作为标题。
下面是几条关于使用<section>的禁忌:
不要将<section>作为用来设置样式或行为的“钩子”容器,那是<div>的工作。
如果<article>、<aside>或<nav>更 符合状况,不要使用<section>。
不要为没有标题的内容区块使用<section>。
|
|