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


Posted in HTML / CSS onOctober 17, 2008

由于缺少结构,即使是形式良好的 HTML 页面也比较难以处理。必须分析标题的级别,才能看出各个部分的划分方式。边栏、页脚、页眉、导航条、主内容区和各篇文章都由通用的 div 元素来表示。HTML 5 添加了一些新元素,专门用来标识这些常见的结构:
 · section:这可以是书中的一章或一节,实际上可以是在 HTML 4 中有自己的标题的任何东西
 · header:页面上显示的页眉;与 head 元素不一样
 · footer:页脚;可以显示电子邮件中的签名
 · nav:指向其他页面的一组链接
 · article:blog、杂志、文章汇编等中的一篇文章

我们来考虑一个典型的 blog 主页,它的顶部有页眉,底部有页脚,还有几篇文章、一个导航区和一个边栏,见代码1 典型的 blog 页面
<html>
<head>
<title>Mokka mit Schlag </title>
</head>
<body>
<div id="page">
<div id="header">
<h1><a href="http://www.elharo.com/blog">Mokka mit Schlag</a></h1>
</div>
<div id="container">
<div id="center" class="column">
<div class="post" id="post-1000572">
<h2><a href=
"/blog/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 <a
href="http://www.wired.com/science/discoveries/news/
2007/04/cone_sf">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.elharo.com/blog">Mokka mit Schlag</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 <a
href="http://www.wired.com/science/discoveries/news/
2007/04/cone_sf">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 属性,从标准的元素名就可以推断出各个部分的意义。这对于音频浏览器、手机浏览器和其他非标准浏览器尤其重要。

(待续)

HTML / CSS 相关文章推荐
一款纯css3制作的2015年元旦雪人动画特效教程
Dec 29 HTML / CSS
纯CSS3打造属于自己的“小黄人”
Mar 14 HTML / CSS
详解css3中的伪类before和after常见用法
Nov 17 HTML / CSS
HTML5的结构和语义(5):交互
Oct 17 HTML / CSS
Html5实现iPhone开机界面示例代码
Jun 30 HTML / CSS
HTML5 Canvas之测试浏览器是否支持Canvas的方法
Jan 01 HTML / CSS
Web时代变迁及html5与html4的区别
Jan 06 HTML / CSS
详解HTML5中表单验证的8种方法介绍
Dec 19 HTML / CSS
HTML5新特性 多线程(Worker SharedWorker)
Apr 24 HTML / CSS
使用placeholder属性设置input文本框的提示信息
Feb 19 HTML / CSS
AmazeUI 缩略图的实现示例
Aug 18 HTML / CSS
基于CSS制作创意端午节专属加载特效
Jun 01 HTML / CSS
HTML5的结构和语义(4):语义性的内联元素
Oct 17 #HTML / CSS
HTML5中语义化 b 和 i 标签
Oct 17 #HTML / CSS
HTML5的结构和语义(5):内嵌媒体
Oct 17 #HTML / CSS
HTML5的结构和语义(5):交互
Oct 17 #HTML / CSS
HTML5 语义化结构化规范化
Oct 17 #HTML / CSS
HTML5 与 XHTML2
Oct 17 #HTML / CSS
X/HTML5 和 XHTML2
Oct 17 #HTML / CSS
You might like
PHP中遍历stdclass object的实现代码
2011/06/09 PHP
PHP性能优化工具篇Benchmark类调试执行时间
2011/12/06 PHP
如何利用php array_multisort函数 对数据库结果进行复杂排序
2013/06/08 PHP
php实现购物车功能(上)
2020/07/23 PHP
CI框架简单分页类用法示例
2020/06/06 PHP
基于jQuery的Spin Button自定义文本框数值自增或自减
2010/07/17 Javascript
js判断上传文件类型判断FileUpload文件类型代码
2014/05/20 Javascript
jQuery操作动态生成的内容的方法
2016/05/28 Javascript
浅谈JS运算符&amp;&amp;和|| 及其优先级
2016/08/10 Javascript
angularjs 源码解析之scope
2016/08/22 Javascript
关于json字符串与实体之间的严格验证代码
2016/11/10 Javascript
jQuery插件HighCharts实现的2D对数饼图效果示例【附demo源码下载】
2017/03/09 Javascript
详解webpack多页面配置记录
2018/01/22 Javascript
js实现点击按钮复制文本功能
2020/07/20 Javascript
详解angular2.x创建项目入门指令
2018/10/11 Javascript
Node.js使用supervisor进行开发中调试的方法
2019/03/26 Javascript
vue实现输入一位数字转汉字功能
2019/12/13 Javascript
基于Python的身份证号码自动生成程序
2014/08/15 Python
python使用xmlrpclib模块实现对百度google的ping功能
2015/06/02 Python
Django中对数据查询结果进行排序的方法
2015/07/17 Python
python实现飞机大战微信小游戏
2020/03/21 Python
python 利用turtle库绘制笑脸和哭脸的例子
2019/11/23 Python
Visual Studio code 配置Python开发环境
2020/09/11 Python
沙特阿拉伯电子产品和家用电器购物网站:Black Box
2019/07/24 全球购物
上海期货面试题
2014/01/31 面试题
linux系统都有哪些运行级别
2012/04/15 面试题
财务出纳员岗位职责
2013/11/26 职场文书
计算机专业学生求职信分享
2013/12/15 职场文书
致1500米运动员广播稿
2014/02/07 职场文书
护士岗位职责
2014/02/16 职场文书
物流管理专业自荐信
2014/06/23 职场文书
中国梦演讲稿开场白
2014/08/28 职场文书
用电申请报告范文
2015/05/18 职场文书
用Python将库打包发布到pypi
2021/04/13 Python
java设计模式--三种工厂模式详解
2021/07/21 Java/Android
Vue的过滤器你真了解吗
2022/02/24 Vue.js