pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

HTML5中div、article、section的區(qū)別

  最近正在學習html5,剛接觸html5,感覺有點不適應,因為有一些標簽改變了,特別是div, section article這三個標簽,查了一些資料,也試著用html5和css3布局網(wǎng)頁,稍微有點頭緒了,下邊還有一個我剛剛布局好的一個簡單的網(wǎng)頁,供大家參考,先看一下,最起碼心里對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 應用的典型場景有文章的章節(jié)、標簽對話框中的標簽頁、或者論文中有編號的部分。一個網(wǎng)站的主頁可以分成簡介、新聞和聯(lián)系信息等幾部分。其實我對這里傳達信息很感興趣,因為感覺 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 。一般來說,當元素內容明確地出現(xiàn)在文檔大綱中時,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="#">聯(lián)系</a></li>
</ul>
</nav>
</header>
<article id="page-content">
<section>
<hgroup>
<h1>這是一個用HTML5做的網(wǎng)頁</h1>
<h2>HTML5+CSS3網(wǎng)頁</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 以及其他標簽的區(qū)分比較簡單。對于 section 和 article 的區(qū)分乍看比較難,其實重點就是看看這段內容脫離了整體是不是還能作為一個完整的、獨立的內容而存在,這里面的重點又在完整身上。因為其實說起來 section 包含的內容也能算作獨立的一塊,但是它只能算是組成整體的一部分,article 才是一個完整的整體。

【網(wǎng)站聲明】本站除付費源碼經(jīng)過測試外,其他素材未做測試,不保證完整性,網(wǎng)站上部分源碼僅限學習交流,請勿用于商業(yè)用途。如損害你的權益請聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。

相關文檔推薦

這篇文章主要介紹了有關HTML5頁面在iPhoneX適配問題,需要的朋友可以參考下
本篇文章主要介紹了html5中canvas圖表實現(xiàn)柱狀圖的示例,本文使用canvas來實現(xiàn)一個圖表,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
Adobe公司出品的多媒體處理軟件產(chǎn)品線較多,涵蓋了音視頻編輯、圖像處理、平面設計、影視后期等領域。這篇文章主要介紹了Adobe Html5 Extension開發(fā)初體驗圖文教程,非常不錯,需要的朋
這篇文章主要介紹了基于HTML5的WebGL經(jīng)典3D虛擬機房漫游動畫,需要的朋友可以參考下
這篇文章主要介紹了手機端用rem+scss做適配的詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
本篇文章主要介紹了canvas 實現(xiàn) github404動態(tài)效果的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
主站蜘蛛池模板: 贵阳用友软件,贵州财务软件,贵阳ERP软件_贵州优智信息技术有限公司 | 首页 - 张店继勇软件开发工作室 兰州UPS电源,兰州山特UPS-兰州万胜商贸 | ERP企业管理系统永久免费版_在线ERP系统_OA办公_云版软件官网 | 铸铝门厂家,别墅大门庭院大门,别墅铸铝门铜门[十大品牌厂家]军强门业 | 精密冲床,高速冲床等冲压设备生产商-常州晋志德压力机厂 | 脱硝喷枪-氨水喷枪-尿素喷枪-河北思凯淋环保科技有限公司 | 手持气象站_便携式气象站_农业气象站_负氧离子监测站-山东万象环境 | PE拉伸缠绕膜,拉伸缠绕膜厂家,纳米缠绕膜-山东凯祥包装 | 济宁工业提升门|济宁电动防火门|济宁快速堆积门-济宁市统一电动门有限公司 | 江门流水线|江门工作台|江门市伟涛行工业设备有限公司 | 成都珞石机械 - 模温机、油温机、油加热器生产厂家 | 防渗土工膜|污水处理防渗膜|垃圾填埋场防渗膜-泰安佳路通工程材料有限公司 | 铁艺,仿竹,竹节,护栏,围栏,篱笆,栅栏,栏杆,护栏网,网围栏,厂家 - 河北稳重金属丝网制品有限公司 山东太阳能路灯厂家-庭院灯生产厂家-济南晟启灯饰有限公司 | RS系列电阻器,RK_RJ启动调整电阻器,RQ_RZ电阻器-上海永上电器有限公司 | 氢氧化钾厂家直销批发-济南金昊化工有限公司 | 头条搜索极速版下载安装免费新版,头条搜索极速版邀请码怎么填写? - 欧远全 | 耐酸碱胶管_耐腐蚀软管总成_化学品输送软管_漯河利通液压科技耐油耐磨喷砂软管|耐腐蚀化学软管 | 电伴热系统施工_仪表电伴热保温箱厂家_沃安电伴热管缆工业技术(济南)有限公司 | 扬州汇丰仪表有限公司| 电动高尔夫球车|电动观光车|电动巡逻车|电动越野车厂家-绿友机械集团股份有限公司 | 复合肥,化肥厂,复合肥批发,化肥代理,复合肥品牌-红四方 | 兰州牛肉面加盟,兰州牛肉拉面加盟-京穆兰牛肉面 | 砂尘试验箱_淋雨试验房_冰水冲击试验箱_IPX9K淋雨试验箱_广州岳信试验设备有限公司 | 列管冷凝器,刮板蒸发器,外盘管反应釜厂家-无锡曼旺化工设备有限公司 | 圣才学习网-考研考证学习平台,提供万种考研考证电子书、题库、视频课程等考试资料 | 超高频感应加热设备_高频感应电源厂家_CCD视觉检测设备_振动盘视觉检测设备_深圳雨滴科技-深圳市雨滴科技有限公司 | 微型气泵-真空-蠕动-水泵-厂家-深圳市品亚科技有限公司 | 无负压供水设备,消防稳压供水设备-淄博创辉供水设备有限公司 | 数控走心机-走心机价格-双主轴走心机-宝宇百科 | 今日热点_实时热点_奇闻异事_趣闻趣事_灵异事件 - 奇闻事件 | 生物制药洁净车间-GMP车间净化工程-食品净化厂房-杭州波涛净化设备工程有限公司 | 武汉宣传片制作-视频拍摄-企业宣传片公司-武汉红年影视 | 电镀标牌_电铸标牌_金属标贴_不锈钢标牌厂家_深圳市宝利丰精密科技有限公司 | 加中寰球移民官网-美国移民公司,移民机构,移民中介,移民咨询,投资移民 | 苏州伊诺尔拆除公司_专业酒店厂房拆除_商场学校拆除_办公楼房屋拆除_家工装拆除拆旧 | 苗木价格-苗木批发-沭阳苗木基地-沭阳花木-长之鸿园林苗木场 | 台湾阳明固态继电器-奥托尼克斯光电传感器-接近开关-温控器-光纤传感器-编码器一级代理商江苏用之宜电气 | 苏州西朗门业-欧盟CE|莱茵UL双认证的快速卷帘门品牌厂家 | 影像测量仪_三坐标测量机_一键式二次元_全自动影像测量仪-广东妙机精密科技股份有限公司 | 螺杆式冷水机-低温冷水机厂家-冷冻机-风冷式-水冷式冷水机-上海祝松机械有限公司 | 杭州网络公司_百度SEO优化-外贸网络推广_抖音小程序开发-杭州乐软科技有限公司 |