久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

HTML5中div、article、section的區別及使用介紹_html5教

HTML5中div、article、section的區別及使用介紹_html5教程技巧HTML5中文學習網,是中國最大的HTML5中文門戶,為廣大HTML5愛好者提供各種HTML5資料,包括HTML5網站、HTML5資訊、HTML5應用、HTML5游戲、
點評:div, section article這三個標簽的基本概念想必大家對其不是很了解下,語義是從無到有,逐漸增強,下面有一個簡單的網頁,供大家參考,希望可以對html5的結構有所熟悉
最近正在學習html5,剛接觸html5,感覺有點不適應,因為有一些標簽改變了,特別是div, section article這三個標簽,查了一些資料,也試著用html5和css3布局網頁,稍微有點頭緒了,下邊還有一個我剛剛布局好的一個簡單的網頁,供大家參考,先看一下,最起碼心里對html5的結構有些概念。

div

HTML Spec: “The div element has no special meaning at all.”

這個標簽是我們見得最多、用得最多的一個標簽。本身沒有任何語義,用作布局以及樣式化或腳本的鉤子(hook)。

section
HTML Spec: “The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading.”

與 div 的無語義相對,簡單地說 section 就是帶有語義的 div 了,但是千萬不要覺得真得這么簡單。section 表示一段專題性的內容,一般會帶有標題。看到這里,我們也許會想到,那么一篇博客文章,或者一條單獨的評論豈不是正好可以用 section 嗎?接著看:

“Authors are encouraged to use the article element instead of the section element when it would make sense to syndicate the contents of the elemen.”

當元素內容聚合起來更加言之有物時,應該使用 article 來替換 section 。

那么,section 應該什么時候用呢?再接著看:

“Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site’s home page could be split into sections for an introduction, news items, and contact information.”

section 應用的典型場景有文章的章節、標簽對話框中的標簽頁、或者論文中有編號的部分。一個網站的主頁可以分成簡介、新聞和聯系信息等幾部分。其實我對這里傳達信息很感興趣,因為感覺 section 和下面要介紹的 artilce 更加適用于模塊化應用,這個話題以后會出篇專門的文章來討論,這里暫時略過。

要注意,W3C 還警告說:

“The section element is not a generic container element. When an element is needed for styling purposes or as a convenience for scripting, authors are encouraged to use the div element instead. A general rule is that the section element is appropriate only if the element’s contents would be listed explicitly in the document’s outline.”

section 不僅僅是一個普通的容器標簽。當一個標簽只是為了樣式化或者方便腳本使用時,應該使用 div 。一般來說,當元素內容明確地出現在文檔大綱中時,section 就是適用的。

article
HTML Spec: “The article element represents a self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication.”

article 是一個特殊的 section 標簽,它比 section 具有更明確的語義, 它代表一個獨立的、完整的相關內容塊。一般來說, article 會有標題部分(通常包含在 header 內),有時也會 包含 footer 。雖然 section 也是帶有主題性的一塊內容,但是無論從結構上還是內容上來說,article 本身就是獨立的、完整的。

HTML Spec 中接著又列舉了一些 article 適用的場景。 “This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.”

當 article 內嵌 article 時,原則上來說,內部的 article 的內容是和外層的 article 內容是相關的。例如,一篇博客文章中,包含用戶提交的評論的 article 就應該潛逃在包含博客文章 article 之中。

問題是怎么才算“完整的獨立內容”?有個最簡單的判斷方法是看這段內容在 RSS feed 中是不是完整的。看這段內容脫離了所在的語境,是否還是完整的、獨立的。

例子:

html頁面:

復制代碼
代碼如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>初學html5</title>
<!--meta tags-->
<meta name="keywords" content="">
<meta name="description" content="">
<!--stylesheets-->
<link rel="stylesheet" href="css/common.css" type="text/css">
<link rel="stylesheet" href="css/layout.css" type="text/css">
<link rel="stylesheet" href="css/reset.css" type="text/css">
<!--javascript-->
<script src="js/jquery-1.3.2.min.js"></script>
<!--conditional comments-->
<!--[if IE]>
<script src="js/html5.js"></script>
<![endif]-->
</head>
<body class="home">
<div id="container">
<header id="page-header">
<div id="logo"><a href="/"><img src="images/graphic-logo.gif" alt="mylogo"></a></div>
<nav id="main-navigation">
<ul>
<li class="current"><a href="#">首頁</a></li>
<li style="color:red;"><a href="#">關于</a></li>
<li><a href="#">服務</a></li>
<li><a href="#">信息</a></li>
<li><a href="#">聯系</a></li>
</ul>
</nav>
</header>
<article id="page-content">
<section>
<hgroup>
<h1>這是一個用HTML5做的網頁</h1>
<h2>HTML5+CSS3網頁</h2>
</hgroup>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elitVivamus ac iaculis erat. Maecenas id fermentum odio. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sagittis porta mauris, iaculis egestas metus posuere sit amet. Sed ullamcorper orci eu dolor egestas sodales. Donec tempor aliquet pulvinar. Sed sed turpis sapien, ac dictum sem. Phasellus metus leo, gravida in imperdiet sit amet, bibendum id magna. Vivamus ac nunc tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis justo ligula. Suspendisse sodales ultricies consequat. Aenean condimentum eros mi. Duis consectetur placerat vehicula. Fusce vel massa erat.</p>
<h2>A demonstration of list items</h2>
<ul>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
</ul>
<ol>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
<li>Lorem ipsum dolor sit amet</li>
</ol>
</section>
<aside>
<h2>這就是aside部分的內容</h2>
<p>Aliquam id lorem ac tellus fringilla bibendum et at turpis. In ut auctor justo. Integer ac quam sed est semper hendrerit. Aenean vulputate interdum augue, sed dapibus mi ultricies convallis. Curabitur a nunc nisi, ac ornare nisi. Ut semper placerat accumsan. Cras eu nibh lorem. Sed sit amet ligula vitae orci molestie sollicitudin sit amet at odio. Mauris non elit ac ipsum facilisis eleifend. Maecenas eu velit sit amet neque iaculis dapibus. Integer mollis est id erat dignissim blandit. Quisque malesuada mattis sollicitudin. Pellentesque volutpat pellentesque luctus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed cursus augue ut sem convallis ullamcorper. Donec vitae magna nec lacus varius pellentesque vel nec diam. Morbi sagittis, magna sit amet sollicitudin ultricies, neque orci fermentum ipsum, non cursus lectus velit at ante. Donec nec neque in sem suscipit faucibus. Aliquam nisi turpis, volutpat quis suscipit in, varius vitae nunc.</p>
</aside>
</article>
</div>
<footer>
&copy; Copyright Dave Woods 2009
</footer>
</body>
</html>

css頁面:


復制代碼
代碼如下:

@charset "utf-8";
/* CSS Document */
#container{
width: 840px;
margin: 20px auto;
background:#fff;
padding:30px;
overflow:hidden;
}
/*--------------- header ----------------*/
#main-navigation{
border-bottom:5px solid #666;
}
#main-navigation ul{
overflow:hidden;
width:100%;
list-style:none;
font-size:1.6em;
}
#main-navigation li{
float:left;
}
#main-navigation li a{
background:#999;
margin: 0 5px 0 0;
padding:5px 30px;
display:block;
color:#fff;
text-decoration:none;
}
#main-navigation li.current a{
background:#666;
}
#main-navigation li a:hover{
background:#777;
}
/*-------------------------- article ------------------------*/
article{
width:100%;
overflow:hidden;
}
section{
float:left;
width:500px;
}
/*-------------------------- article ------------------------*/
aside{
float:right;
width:310px;
}
/*-------------------------- article ------------------------*/
footer{
width:840px;
margin:20px auto;
font-size:1.4em;
text-align:center;
}

總結:
div section article ,語義是從無到有,逐漸增強的。div 無任何語義,僅僅用作樣式化或者腳本化的鉤子(hook),對于一段主題性的內容,則就適用 section,而假如這段內容可以脫離上下文,作為完整的獨立存在的一段內容,則就適用 article。原則上來說,能使用 article 的時候,也是可以使用 section 的,但是實際上,假如使用 article 更合適,那么就不要使用 section 。nav 和 aside 的使用也是如此,這兩個標簽也是特殊的 section,在使用 nav 和 aside 更合適的情況下,也不要使用 section 了。

對于 div 和 section、 article 以及其他標簽的區分比較簡單。對于 section 和 article 的區分乍看比較難,其實重點就是看看這段內容脫離了整體是不是還能作為一個完整的、獨立的內容而存在,這里面的重點又在完整身上。因為其實說起來 section 包含的內容也能算作獨立的一塊,但是它只能算是組成整體的一部分,article 才是一個完整的整體。

最后附上我的首個html5頁面源碼:http://xiazai.jb51.net/201308/yuanma/demoh5_jb51.net.rar
【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。
主站蜘蛛池模板: 天堂在线91 | 中文字字幕一区二区三区四区五区 | 天天宗合网 | 精品亚洲永久免费精品 | 日本黄色的视频 | 成人国产a| 精品国产乱码久久久久久闺蜜 | 欧美色专区 | 国产精品国产精品国产专区不蜜 | 亚洲成人高清 | 亚洲欧美视频一区 | av毛片 | 国产乡下妇女做爰 | 国产精品久久久久久久 | 夜夜夜久久久 | 精一区二区 | 亚洲视频一区二区三区四区 | 99久久国产综合精品麻豆 | 日韩精品成人av | 中文字幕一区二区三区不卡 | 成人伊人 | 国产精品成人一区二区 | 狠狠久| 日本亚洲一区二区 | 午夜成人在线视频 | 欧美一级久久 | 一区二区三区在线 | 国产精品视频一区二区三区四蜜臂 | 国产免费播放视频 | 亚洲视频免费观看 | 亚洲一区二区三区免费在线观看 | 成人不卡 | 一区二区三区视频在线免费观看 | 日韩精品久久久久 | 精品国产一区二区三区久久久久久 | 国产综合久久久久久鬼色 | 日韩视频一区二区三区 | 中文字幕精品一区二区三区在线 | 81精品国产乱码久久久久久 | 免费小视频在线观看 | 亚洲免费成人 |