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 按钮 利用css3实现超酷下载按钮
Mar 18 HTML / CSS
css3高级选择器使用方法
Dec 02 HTML / CSS
css3实现3d旋转动画特效
Mar 10 HTML / CSS
CSS3选择器新增问题的实现
Jan 21 HTML / CSS
html5使用canvas画三角形
Dec 15 HTML / CSS
Html5调用手机摄像头并实现人脸识别的实现
Dec 21 HTML / CSS
H5页面适配iPhoneX(就是那么简单)
Dec 02 HTML / CSS
html5手机键盘弹出收起的处理
Jan 20 HTML / CSS
amazeui页面校验功能的实现代码
Aug 24 HTML / CSS
六种css3实现的边框过渡效果
Apr 22 HTML / CSS
css3新特性的应用示例分析
Mar 16 HTML / CSS
详解CSS中postion和opacity及cursor的特性
Aug 14 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 上传功能实例代码
2010/04/13 PHP
20个PHP常用类库小结
2011/09/11 PHP
PHP+Mysql+jQuery实现动态展示信息
2011/10/08 PHP
PHP字符串比较函数strcmp()和strcasecmp()使用总结
2014/11/19 PHP
微信封装的调用微信签名包的类库
2017/06/08 PHP
Laravel5.4框架中视图共享数据的方法详解
2019/09/05 PHP
在Laravel中使用GuzzleHttp调用第三方服务的API接口代码
2019/10/15 PHP
基于jquery扩展漂亮的CheckBox(自己编写)
2013/11/19 Javascript
JS对象转换为Jquery对象实现代码
2013/12/29 Javascript
jQuery实现Meizu魅族官方网站的导航菜单效果
2015/09/14 Javascript
JavaScript数组去重由慢到快由繁到简(优化篇)
2016/08/26 Javascript
基于vue+canvas的excel-like组件实例详解
2017/11/28 Javascript
JS动画定时器知识总结
2018/03/23 Javascript
JS实现的缓冲运动效果示例
2018/04/30 Javascript
vue检测对象和数组的变化分析
2018/06/30 Javascript
vue-cli项目代理proxyTable配置exclude的方法
2018/09/20 Javascript
基于Web Audio API实现音频可视化效果
2020/06/12 Javascript
详解Python中的装饰器、闭包和functools的教程
2015/04/02 Python
使用python搭建服务器并实现Android端与之通信的方法
2019/06/28 Python
python按键按住不放持续响应的实例代码
2019/07/17 Python
python3的url编码和解码,自定义gbk、utf-8的例子
2019/08/22 Python
在Python中预先初始化列表内容和长度的实现
2019/11/28 Python
Python zip函数打包元素实例解析
2019/12/11 Python
Python如何急速下载第三方库详解
2020/11/02 Python
Kendra Scott官网:美国领先的时尚配饰品牌
2020/10/22 全球购物
.net面试题
2015/12/22 面试题
高中生自我评价个人范文
2013/11/09 职场文书
护士自我评价
2014/02/01 职场文书
文明风采获奖感言
2014/02/18 职场文书
旅游与环境专业求职信
2014/06/05 职场文书
新农村建设汇报材料
2014/08/15 职场文书
2015年财务试用期工作总结
2014/12/24 职场文书
军训个人总结
2015/03/03 职场文书
出纳试用期自我评价
2015/03/10 职场文书
Matplotlib绘制混淆矩阵的实现
2021/05/27 Python
JavaScript与JQuery框架基础入门教程
2021/07/15 Javascript