首頁  >  文章  >  web前端  >  HTML5語意化標記Section與Article實例詳解

HTML5語意化標記Section與Article實例詳解

伊谢尔伦
伊谢尔伦原創
2017-06-16 11:01:111707瀏覽
網頁製作cnn6文章簡介:最常被問到的問題是:在什麼情況下我們應該使用這些元素?以及我們應該如何正確的使用這些元素?

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

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

Section元素

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

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

#從描述中我們可以看出2f8332c8dcfd5c7dec030a070bf652c3元素的作用就是分段,或多或少類似e388a4556c0f65e1904146cc1a846bee。但它仍有一個特例。在文件中,加入了一段特別聲明:

「當一個元素僅用於風格樣式或是為了腳本的方便,我們鼓勵作者使用e388a4556c0f65e1904146cc1a846bee。2f8332c8dcfd5c7dec030a070bf652c3元素適用於,當元素的內容需要明確的列出時。 ,但是當有複雜的樣式或腳本時,我們仍建議使用p元素。

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

因此在現實例子中,使用2f8332c8dcfd5c7dec030a070bf652c3元素的原因是結構化的列出部落格的內容,程式碼如下:

<p 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>  
</p>

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

Article元素

從名字上,它已經很好的詮釋了自己,但是我們仍要看看官方文件上是如何描述它的:

#「在文檔,頁面,應用或是站點上的一個獨立部分,並且大體上,是可獨立分配,或是重複使用的,例如在發佈時。的評論,互動的小工具或小工具,或任何其他獨立項目的內容。發布的,例如博客,頁面內容或是論壇帖子。

以下範例給出如何使用23c3de37f2f9ebcb477c4a90aac6fffd建立一個部落格文章。

<article class="post">  
    <header>  
    <h1>This is Blog Post Title</h1>  
    <p class="post-meta">  
        <ul>  
            <li class="author">Author Name</li>  
            <li class="categories">Save in Categories</li>  
        </ul>  
    </p>  
    </header>  

    <p class="post-content">  
        Sweet roll halvah biscuit toffee liquorice tart pudding sesame snaps.   
        Biscuit powder jelly-o fruitcake faworki chocolate bar. Pudding oatnbon. Gummies   
        halvah gummies danish biscuit applicak   
        cake tootsie roll sesame snaps lollipop gingerbread boe gingerbread jelly-o pastry.  
    </p>  

</article>

 此外,23c3de37f2f9ebcb477c4a90aac6fffd元素還可與section元素結合,需要的時候,可以使用2f8332c8dcfd5c7dec030a070bf652c3元素將文章分為幾個段落,如下例所示。

<article class="post">  
    <header>  
    <h1>This is Blog Post Title</h1>  
    <p class="post-meta">  
        <ul>  
            <li class="author">Author Name</li>  
            <li class="categories">Save in Categories</li>  
        </ul>  
    </p>  
    </header>  

    <p 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>  
    </p>  

</article>

總結

如萬維網的創始人和W3C的董事所預測的那般,所有HTML5創造出來的新元素都是為了是網絡結構更加語義化。如何正確的應用這些元素在網頁開發者和設計者之間,仍有爭論。

無論如何,不要混淆觀點。如我之前提出的,只要是合理的情況,且你看到使用了它使得結構變得意義非凡,那麼請用它。

以上是HTML5語意化標記Section與Article實例詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn