溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

HTML5中的Article和Section元素的用法

發(fā)布時(shí)間:2021-08-25 18:29:57 來(lái)源:億速云 閱讀:143 作者:chen 欄目:web開(kāi)發(fā)

這篇文章主要介紹“HTML5中的Article和Section元素的用法”,在日常操作中,相信很多人在HTML5中的Article和Section元素的用法問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”HTML5中的Article和Section元素的用法”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!



Section元素
這 是一個(gè)最容易產(chǎn)生歧義的元素。它與<div>元素有什么區(qū)別?我們一直在用<div>來(lái)劃分段落,所以除 了<div>,我們什么時(shí)候使用這個(gè)元素。我們引用官方文檔來(lái)闡述它。根據(jù)WHATWG文檔,對(duì)<section>元素做了以下 描述:
“<section>元素表示了一篇文檔或應(yīng)用中,通用段落 - WHATWG”

從描述中我們可以看出<section>元素的作用就是分段,或多或少類似于<div>。但是它仍有一個(gè)特例。在文檔中,加入了一段特別聲明:
“當(dāng)一個(gè)元素僅用于風(fēng)格樣式或是為了腳本的方便,我們鼓勵(lì)作者使用<div>。<section>元素適用于,當(dāng)元素的內(nèi)容需要明確的列出時(shí)。- WHATWG”

基于這一點(diǎn),我們可以總結(jié)以下兩點(diǎn)
第一,盡管section元素在技術(shù)上是可以設(shè)計(jì)樣式的,但是當(dāng)有復(fù)雜的樣式或腳本時(shí),我們?nèi)越ㄗh使用div元素。
第二,類似于<li>元素,section元素是用來(lái)列舉內(nèi)容的。

因此在現(xiàn)實(shí)例子中,使用<section>元素的原因是結(jié)構(gòu)化的列出博客的內(nèi)容,代碼如下:

代碼如下:


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


這只是個(gè)例子,<section>元素也可以用作其他用途。

Article元素
從名字上,它已經(jīng)很好的詮釋了自己,但是我們?nèi)砸纯垂俜轿臋n上是如何描述它的:
“在文檔,頁(yè)面,應(yīng)用或是站點(diǎn)上的一個(gè)獨(dú)立部分,并且大體上,是可獨(dú)立分配,或是重復(fù)使用的,例如在發(fā)布時(shí)。這個(gè)可以是論壇帖子,雜志或是新聞,博客條目,用戶提交的評(píng)論,互動(dòng)的小工具或小工具,或任何其他獨(dú)立項(xiàng)目的內(nèi)容?!?

從上描述中,我們可以總結(jié)出<article>元素專用于結(jié)構(gòu)化文章,特別是我們要發(fā)布的,例如博客,頁(yè)面內(nèi)容或是論壇帖子。
以下例子給出了如何使用<article>構(gòu)建一個(gè)博客文章。

代碼如下:


<article class="post">
<header>
<h2>This is Blog Post Title</h2>
<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>


此外,<article>元素還可與section元素結(jié)合,需要的時(shí)候,可以使用<section>元素將文章分為幾個(gè)段落,如下例所示。

代碼如下:


<article class="post">
<header>
<h2>This is Blog Post Title</h2>
<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>
<h3>This is the Sub-Heading</h3>
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>
<h4>This is another Sub-Heading</h4>
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&eacute;e jujubes drag&eacute;e drag&eacute;e brownie jelly biscuit. Powder croissant jelly beans pastry.
</section>
</div>
</article>

到此,關(guān)于“HTML5中的Article和Section元素的用法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI