HTML5的结构和语义(2):结构

  由于缺少结构,即使是形式良好的 HTML 页面也比较难以处理。必须分析标题的级别,才能看出各个部分的划分方式。边栏、页脚、页眉、导航条、主内容区和各篇文章都由通用的 div 元素来表示。HTML 5 添加了一些新元素,专门用来标识这些常见的结构:

 · section:这可以是书中的一章或一节,实际上可以是在 HTML 4 中有自己的标题的任何东西

 · header:页面上显示的页眉;与 head 元素不一样

 · footer:页脚;可以显示电子邮件中的签名

 · nav:指向其他页面的一组链接

 · article:blog、杂志、文章汇编等中的一篇文章

  我们来考虑一个典型的 shouchaobao手抄报主页,它的顶部有页眉,底部有页脚,还有几篇文章、一个导航区和一个边栏,见代码1 典型的 blog 页面

<html>

<head>

<title>Mokka mit Schlag </title>

</head>

<body>

<div id="page">

<div id="header">

<h1><a href="http://www.9252.com/shouchaobao/">9252手抄报</a></h1>

</div>

<div id="container">

<div id="center" class="column">

<div class="post" id="post-1000572">

<h2><a href=

"/shouchaobao/birding/2007/04/23/spring-comes-and-goes-in-sussex-county/">

Spring Comes (and Goes) in Sussex County</a></h2>

<div class="entry">

<p>Yesterday I joined the Brooklyn Bird Club for our

annual trip to Western New Jersey, specifically Hyper

Humus, a relatively recently discovered hot spot. It

started out as a nice winter morning when we arrived

at the site at 7:30 A.M., progressed to Spring around

10:00 A.M., and reached early summer by 10:15. </p>

</div>

</div>

<div class="post" id="post-1000571">

<h2><a href=

"/blog/birding/2007/04/23/but-does-it-count-for-your-life-list/">

But does it count for your life list?</a></h2>

<div class="entry">

<p>Seems you can now go 2020 五一劳动节手抄报<a

href="http://www.9252.com/shouchaobao/10749.html">bird watching via the Internet</a>. I

haven't been able to test it out yet (20 user

limit apparently) but this is certainly cool.

Personally, I can't imagine it replacing

actually being out in the field by any small amount.

On the other hand, I've always found it quite

sad to meet senior birders who are no longer able to

hold binoculars steady or get to the park. I can

imagine this might be of some interest to them. At

least one elderly birder did a big year on TV, after

he could no longer get out so much. This certainly

tops that.</p>

</div>

</div>

</div>

<div class="navigation">

<div class="alignleft">

<a href="/blog/page/2/">« _fcksavedurl=""/blog/page/2/">«" Previous Entries</a>

</div>

<div class="alignright"></div>

</div>

</div>

<div id="right" class="column">

<ul id="sidebar">

<li><h2>Info</h2>

<ul>

<li><a href="/blog/comment-policy/">Comment Policy</a></li>

<li><a href="/blog/todo-list/">Todo List</a></li>

</ul></li>

<li><h2>Archives</h2>

<ul>

<li><a href='/blog/2007/04/'>April 2007</a></li>

<li><a href='/blog/2007/03/'>March 2007</a></li>

<li><a href='/blog/2007/02/'>February 2007</a></li>

<li><a href='/blog/2007/01/'>January 2007</a></li>

</ul>

</li>

</ul>

</div>

<div id="footer">

<p>Copyright 2007 Elliotte Rusty Harold</p>

</div>

</div>

</body>

</html>

  即使有正确的缩进,这些嵌套的 div 仍然让人觉得非常混乱。在 HTML 5 中,可以将这些元素替换为语义性的元素,见代码2 用 HTML5编写的典型blog页面

<html>

<head>

<title>Mokka mit Schlag </title>

</head>

<body>

<header>

<h1><a href="http://www.9252.com/shouchaobao/">9252手抄报</a></h1>

</header>

<section>

<article>

<h2><a href=

"/blog/birding/2007/04/23/spring-comes-and-goes-in-sussex-county/">

Spring Comes (and Goes) in Sussex County</a></h2>

<p>Yesterday I joined the Brooklyn Bird Club for our

annual trip to Western New Jersey, specifically Hyper

Humus, a relatively recently discovered hot spot. It

started out as a nice winter morning when we arrived at

the site at 7:30 A.M., progressed to Spring around 10:00

A.M., and reached early summer by 10:15. </p>

</article>

<article>

<h2><a href=

"/blog/birding/2007/04/23/but-does-it-count-for-your-life-list/">

But does it count for your life list?</a></h2>

<p>Seems you can now go 2020 61儿童节手抄报<a

href="http://www.9252.com/shouchaobao/14065.html">bird watching via the Internet</a>. I

haven't been able to test it out yet (20 user

limit apparently) but this is certainly cool.

Personally, I can't imagine it replacing

actually being out in the field by any small amount.

On the other hand, I've always found it quite

sad to meet senior birders who are no longer able to

hold binoculars steady or get to the park. I can

imagine this might be of some interest to them. At

least one elderly birder did a big year on TV, after

he could no longer get out so much. This certainly

tops that.</p>

</article>

<nav>

<a href="/blog/page/2/">« _fcksavedurl=""/blog/page/2/">«" Previous Entries</a>

</nav>

</section>

<nav>

<ul>

<li><h2>Info</h2>

<ul>

<li><a href="/blog/comment-policy/">Comment Policy</a></li>

<li><a href="/blog/todo-list/">Todo List</a></li>

</ul></li>

<li><h2>Archives</h2>

<ul>

<li><a href='/blog/2007/04/'>April 2007</a></li>

<li><a href='/blog/2007/03/'>March 2007</a></li>

<li><a href='/blog/2007/02/'>February 2007</a></li>

<li><a href='/blog/2007/01/'>January 2007</a></li>

</ul>

</li>

</ul>

</nav>

<footer>

<p>Copyright 2007 Elliotte Rusty Harold</p>

</footer>

</body>

</html>

  现在不再需要 div 了。不再需要自己设置 class 属性,从标准的元素名就可以推断出各个部分的意义。这对于音频浏览器、手机浏览器和其他非标准浏览器尤其重要。

  (待续)

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,026评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,655评论 1 296
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,726评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,204评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,558评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,731评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,944评论 2 314
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,698评论 0 203
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,438评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,633评论 2 247
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,125评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,444评论 3 255
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,137评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,103评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,888评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,772评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,669评论 2 271

推荐阅读更多精彩内容

  • Chapter 9 Second Report of Dr. Watson THE LIGHT UPON THE ...
    久然丶阅读 597评论 0 2
  • 时间过的很快,眨眼之间,毕业快4年了 4年之间,些许任性,些许幼稚,但是终究会成长 许多人喜欢横向比较,朋辈来说,...
    乐看世界阅读 556评论 0 0
  • 我最喜欢的季节是冬季。因为冬季就下雪了,下雪了就可以堆雪人,打雪仗,下雪结冰了还可以滑冰。虽然冬季很冷,但我还是很...
    仝彤阅读 258评论 0 0
  • 阿紫问萧峰:“她有什么好,我哪里及不上她,你老是想着她,老是忘不了她?” 萧峰平静的答:“你样样...
    芷祉阅读 209评论 0 0
  • 姓名:赵宗明 学号:19021211230 【嵌牛导读】:STM32 串口通信 数据包 【嵌牛鼻子】:利用电脑...
    JS_Terry_M阅读 1,113评论 0 1