HTML5 教程学习 - footer元素标签

w3c-html5-logo-viiiix长久以来,我们习惯于使用<div id="footer">这样的代码作为页面的页脚。在HTML5中,我们可以使用用途更广、扩展性更强的<footer>元素了。根据W3C的定义规范:

footer元素可以作为其直接父级内容区块或是一个根区块的结尾。footer通常包括其相关区块的附加信息,如作者、相关阅读链接以及版权信息等。

The footer element represents a footer for its nearest ancestor sectioning content or sectioning root element. A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.

怎样使用<footer>元素?

目前,我们通常使用类似下面这样的代码来写页面的页脚:

<div id="footer">
  <ul>
     <li>copyright</li>
     <li>sitemap</li>
     <li>contact</li>
     <li>to top</li>
  </ul>
<div>

在HTML5中,我们可以不使用div,而用更加语义化的footer来写:

<footer>
  <ul>
     <li>copyright</li>
     <li>sitemap</li>
     <li>contact</li>
     <li>to top</li>
  </ul>
</footer>

在同一个页面中可以使用多个<footer>元素,即可以用作页面整体的页脚,也可以作为一个内容区块的结尾,例如,我们可以将<footer>直接写在<section>或是<article>中:

<section>
   Section content appears here.
   <footer>
      Footer information for section.
   </footer>
</section>
<article>
   Article content appears here.
   <footer>
      Footer information for article.
   </footer>
</article>

译者:Viiiix7210

原文参考:html5doctor.comW3C HTML5 规范


收藏与分享