• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com专业计算机教程网站
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure
您的位置:首页 > 网页设计 >html5 > 详解HTML5中div和section以及article的区别_html5教程技巧

详解HTML5中div和section以及article的区别_html5教程技巧

作者:匿名 字体:[增加 减小] 来源:互联网 时间:2018-12-03

本文主要包含HTML5,div,section,article等相关知识,匿名希望在学习及工作中可以帮助到您
刚刚开始接触 HTML5 时,对它的标签很不适应,甚至一度有点反感。尤其是对 div、section、article 这几个标签,实在弄不清楚应该使用在什么场合下。
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 就是适用的。

  1. <article>
  2. <hgroup> <h1>Applesh1> <h2>Tasty, delicious fruit!h2> hgroup>
  3. <p>The apple is the pomaceous fruit of the apple tree.p>
  4. <section>
  5. <h1>Red Delicioush1>
  6. <p>These bright red apples are the most common found in many supermarkets.p>
  7. section>
  8. <section>
  9. <h1>Granny Smithh1>
  10. <p>These juicy, green apples make a great filling for apple pies.p>
  11. section>
  12. article>

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 中是不是完整的。看这段内容脱离了所在的语境,是否还是完整的、独立的。

例子:

  1. <article>
  2. <header>
  3. <h1>The Very First Rule of Lifeh1>
  4. <p><time pubdate datetime="2009-10-09T14:28-08:00">time>p>
  5. header>
  6. <p>If there's a microphone anywhere near you, assume it's hot and sending whatever you're saying to the world. Seriously.p>
  7. <

您可能想查找下面的文章:

  • HTML5知识点总结
  • HTML5的本地存储
  • HTML5本地存储之IndexedDB
  • Html5实现文件异步上传功能
  • Html5新标签datalist实现输入框与后台数据库数据的动态匹配
  • 详解HTML5 window.postMessage与跨域
  • HTML5拖放API实现拖放排序的实例代码
  • 解决html5中video标签无法播放mp4问题的办法
  • HTML5新特性 多线程(Worker SharedWorker)
  • Html5新增标签有哪些

相关文章

  • 2018-12-03为什么视频网站在桌面端依然采用Flash而不是HTML5?
  • 2018-12-03HTML5网页版黑白子五子棋游戏的示例代码分享
  • 2017-08-06html5 offlline 缓存使用示例
  • 2018-12-03自定义实现可以播放暂停、进度拖拽、音量控制及全屏的H5播放器
  • 2018-12-03phonegap播放音频详解
  • 2018-12-03HTML5 拖放功能实现代码
  • 2018-12-03CSS+HTML5的使用方法实例
  • 2018-12-03HTML5每日一练之mark标签的应用
  • 2018-12-03HTMLcanvas矩形阵雨
  • 2018-12-03用仿ActionScript的语法来编写html5——第七篇,自定义按钮

文章分类

  • html/xhtml
  • html5
  • CSS
  • XML/XSLT
  • Dreamweaver教程
  • Frontpage教程
  • 心得技巧
  • bootstrap
  • vue
  • AngularJS
  • HBuilder教程
  • css3
  • 浏览器兼容
  • div/css
  • 网页编辑器
  • axure

最近更新的内容

    • 用HTML5开发App真的好嘛?
    • 简单介绍HTML5中的文件导入_html5教程技巧
    • canvas需要在标签里直接定义宽高
    • HTML5中meta属性的使用代码示例详解
    • 详细介绍HTML5游戏开发5条建议及开发工具分享
    • 如何在网站头部添加视频海报?添加视频海报的方法(代码示例)
    • H5富文本编辑器的详细介绍
    • 百行 HTML5 代码实现四种双人对弈游戏
    • JS的图片处理与合成详解
    • HTML5 离线应用之打造零请求、无流量网站的解决方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有