HTML5中的Article和Section元素

來源:互聯網
上載者:User

標籤:jquery   ui   web前端   前端   架構   

HTML5帶出了一系列新元素,並且將在未來被廣泛應用。然而,有一些元素在使用時易被混淆,包括以下兩個新元素:和。


      最常被問起的問題是:在什麼情況下我們應該使用這些元素?以及我們應該如何正確的使用這些元素?

      Section元素

      這是一個最容易產生歧義的元素。它與元素有什麼區別?我們一直在用來劃分段落,所以除 了,我們什麼時候使用這個元素。我們引用官方文檔來闡述它。根據WHATWG文檔,對元素做了以下 描述:

“元素表示了一篇文檔或應用中,通用段落 - WHATWG”

精心開發5年的UI前端架構! 
      從描述中我們可以看出元素的作用就是分段,或多或少類似於。但是它仍有一個特例。在文檔中,加入了一段特別聲明:

“當一個元素僅用於風格樣式或是為了指令碼的方便,我們鼓勵作者使用。元素適用於,當元素的內容需要明確的列出時。- WHATWG”


      基於這一點,我們可以總結以下兩點:

      第一,儘管section元素在技術上是可以設計樣式的,但是當有複雜的樣式或指令碼時,我們仍建議使用div元素。

      第二,類似於元素,section元素是用來列舉內容的。


      因此在現執行個體子中,使用元素的原因是結構化的列出部落格的內容,代碼如下:

<div class="blog">      <section class="post">          <h2 class="post-title">Blog Post Title</h2>          <p class="post-excerpt">Ice cream tart powder jelly-o.           Gummies chocolate cake ice cream cookie halvah tiramisu jelly-o.</p>      </section>      <section class="post">          <h2 class="post-title">Blog Post Title</h2>          <p class="post-excerpt">Ice cream tart powder jelly-o.           Gummies chocolate cake ice cream cookie halvah tiramisu jelly-o.</p>      </section>      <section class="post">          <h2 class="post-title">Blog Post Title</h2>          <p class="post-excerpt">Ice cream tart powder jelly-o.           Gummies chocolate cake ice cream cookie halvah tiramisu jelly-o.</p>      </section>  </div>
 

      這隻是個例子,元素也可以用作其他用途。


      Article元素

      從名字上,它已經很好的詮釋了自己,但是我們仍要看看官方文檔上是如何描述它的:精心開發5年的UI前端架構!

“在文檔,頁面,應用或是網站上的一個獨立部分,並且大體上,是可獨立分配,或是重複使用的,例如在發布時。這個可以是論壇文章,雜誌或是新聞,部落格條目,使用者提交的評論,互動的小工具或小工具,或任何其他獨立項目的內容。”


      從上描述中,我們可以總結出元素專用於結構化文章,特別是我們要發布的,例如部落格,頁面內容或是論壇文章。

以下例子給出了如何使用構建一個部落格文章。

<article class="post">      <header>      <h1>This is Blog Post Title</h1>      <div class="post-meta">          <ul>              <li class="author">Author Name</li>              <li class="categories">Save in Categories</li>          </ul>      </div>      </header>           <div class="post-content">          Sweet roll halvah biscuit toffee liquorice tart pudding sesame snaps.           Biscuit powder jelly-o fruitcake faworki chocolate bar. Pudding oat           cake tootsie roll sesame snaps lollipop gingerbread bonbon. Gummies           halvah gummies danish biscuit applicake gingerbread jelly-o pastry.      </div>       </article>
 

      此外,元素還可與section元素結合,需要的時候,可以使用元素將文章分為幾個段落,如下例所示。 精心開發5年的UI前端架構!

<article class="post">      <header>      <h1>This is Blog Post Title</h1>      <div class="post-meta">          <ul>              <li class="author">Author Name</li>              <li class="categories">Save in Categories</li>          </ul>      </div>      </header>           <div class="post-content">          <section>          <h2>This is the Sub-Heading</h2>          Sweet roll halvah biscuit toffee liquorice tart pudding sesame snaps.           Biscuit powder jelly-o fruitcake faworki chocolate bar. Pudding oat cake           tootsie roll sesame snaps lollipop gingerbread bonbon. Gummies halvah           gummies danish biscuit applicake gingerbread jelly-o pastry.          </section>               <section>          <h3>This is another Sub-Heading</h3>          Topping cheesecake sweet pie carrot cake sweet roll. Gummi bears lemon drops          toffee sesame snaps tart topping chupa chups apple pie gummies. Wafer chocolate          cake. Sugar plum chocolate bar topping ice cream carrot cake danish bonbon.           Cheesecake gummi bears dragée jujubes dragée dragée brownie jelly biscuit. Powder croissant jelly beans pastry.          </section>      </div>       </article>
 

總結
      所有HTML5創造出來的新元素都是為了是網路結構更加語義化。

HTML5中的Article和Section元素

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.