萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> XML 程式設計

HTML5 學習筆記(三):hgroup、header、footer、address、nav 新元素詳解

<hgroup> 元素

用於將標題與副標題分組,避免在大綱中產生多層級標題。範例:

<hgroup>
 <h1>Welcome to my WWF</h1>
 <h2>For a living planet</h2>
</hgroup>
<p>The rest of the content...</p>

<header> 元素

具引導與導航功能的輔助元素,通常包含區塊標題(<h1>-<h6> 或 <hgroup>),也可含搜尋表單、Logo、資料表甚至 <nav>(依最新規範)。同一頁面可有多個 header(頁面級、文章級皆可)。

<header>
 <h1>The most important heading on this page</h1>
</header>

<article>
 <header>
 <h1>Title of this article</h1>
 </header>
 <p>...Lorem Ipsum dolor set amet...</p>
</article>

<footer> 元素

表示其直接父區塊或根區塊的結尾,常含作者、相關連結、版權等資訊。可替代傳統 <div id="footer">,語義更清晰。同頁可出現多個 footer(頁面級、section 級、article 級)。

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

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

<address> 元素

呈現文檔創建者的聯絡資訊:姓名、網站、Email、實體地址、電話等。不限於「地址」,涵蓋所有相關聯絡方式。範例:

The HTML5 Doctor is run by the following group of volunteers:
<address>
 <a href="https://html5doctor.com/author/jacko">Jack Osborne</a>,
 <a href="https://html5doctor.com/author/richc">Rich Clark</a>,
 <a href="https://html5doctor.com/author/miker">Mike Robinson</a>
</address>

結合 <footer> 與 <time>:

<footer>
 <div class="vcard"> by
 <address class="author">
 <em class="fn"><a title="Posts by Jack Osborne" href="#">Jack Osborne</a></em>
 </address> on
 <time datetime="2009-11-04" class="published updated">November 4th, 2009</time>
 </div>
</footer>

若需顯示非創建者聯絡資訊,建議使用 hCard 微格式。

<nav> 元素

主要導航連結群組(連往其他頁面或頁內區塊)。非所有連結群都需用 nav(如頁腳版權連結用 footer 即可)。傳統導航列寫法:

<nav>
 <ul>
 <li><a href="index.html">Home</a></li>
 <li><a href="/about/">About</a></li>
 <li><a href="/blog/">Blog</a></li>
 </ul>
</nav>

W3C 範例展示頁面級與文章級雙重導航:

<body>
 <h1>The Wiki Center Of Exampland</h1>
 <nav><ul><li><a href="/">Home</a></li><li><a href="/events">Current Events</a></li>...</ul></nav>
 <article>
 <header><h1>Demos in Exampland</h1><p>Written by A. N. Other.</p></header>
 <nav><ul><li><a href="#public">Public demonstrations</a></li><li><a href="#destroy">Demolitions</a></li>...</ul></nav>
 <div>
 <section id="public"><h1>Public demonstrations</h1><p>...</p></section>
 <section id="destroy"><h1>Demolitions</h1><p>...</p></section>
 </div>
 <footer><p><a href="?edit">Edit</a> | <a href="?delete">Delete</a> | <a href="?Rename">Rename</a></p></footer>
 </article>
 <footer><p><small>© copyright 1998 Exampland Emperor</small></p></footer>
</body>
copyright © 萬盛學電腦網 all rights reserved