HTML5标准学习入门之文档结构

推荐专题:HTML 5 下一代Web开发标准详解

创新互联公司,为您提供重庆网站建设公司重庆网站制作、网站营销推广、网站开发设计,对服务报废汽车回收等多个行业拥有丰富的网站建设及推广经验。创新互联公司网站建设公司成立于2013年,提供专业网站制作报价服务,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏心悦目的作品。 与客户共同发展进步,是我们永远的责任!

说起HTML的结构,很多人都能说得头头是道,一般来说答案可能是这样的:

一个DOCTYPE,一个html,里面有head和body元素。

这当然不能说是不正确的,但是如果问到一个最小的HTML源文件必须有哪一些东西的话,恐怕很少有人能正确地做出回答。

先来回答一下这个问题,一个最简的HTML5源码文件需要的内容如下:

 
 
 
  1.  

是的,就这样,一个字符不多,一个字符不少,除了大小写可任意变化外,其他的任何内容都是不能变动的。

那么究竟是怎么样的规则,导致一个最简的源码文件必须有doctype声明呢?根据标准,一个HTML文档有如下内容组成(严格按照顺序):

一个BOM标记,且这个BOM标记必须为U+FEFF。

  • · 0-n个空格或注释。
  • · DOCTYPE声明。
  • · 0-n个空格或注释。
  • · 一个HTML元素。
  • · 0-n个空格或注释。

这里存在着一些和HTML4的不同,一个HTML4的最简源码文件是这样的:

 
 
 
  1.                       "http://www.w3.org/TR/html4/loose.dtd"> 
  2. 这里是标题 

两者的区别是显而易见的:

  • HTML5把DOCTYPE修改为更简单的,这个已经众所周知了。
  • 在HTML4中多了一个标签。</li></ul> <p>这里的重点就是<title>标签了,关于这个标签,在HTML4.01标准中是这么说的:</p><p><strong>Every HTML document must have a TITLE element in the HEAD section.</strong></p><p>也即是说,HTML4要求<title>标签是必须存在的。</p><p>而在HTML5的标准中,又是这么说的:</p><p><strong>There must be no more than one title element per document.</strong></p><p>HTML5中只设定了<title>标签数量的上限,却没有指明下限,也就是说,没有<title>的文档已经被视为一个合法的文档了。</p><p>对于DOCTYPE,HTML4中设定了6种DOCTYPE,HTML5中将DOCTYPE分为3种,这个在以后的章节中再具体说明。</p><p>再回过来看一下文档组成,除去0-n个空格或注释这样并没有多大意义的元素之外,组成的列表中还说明有一个HTML元素,但是最简的源码中却没有这东西。这是因为在HTML的规范中,一直存在“隐式标签”这样的概念,关于隐式标签,大致可以这么解释:</p><p>一部分元素,当满足特定的前提条件时,其开始标签或结束标签可以在源码中省略。在这种情况下,被省略的标签称为“隐式标签”。</p><p>需要注意的是,此处的省略指的是在源码中省略,而在最终成型的DOM树中,这个标签是存在的,因此才称为隐式标签。因此上面最简的源码结构,在生成DOM树后,其真正的结构是这样的:</p> <pre> <ol> <li><!DOCTYPE html> </li> <li><html> </li> <li>    <head></head> </li> <li>    <body></body> </li> <li></html> </li> </ol></pre><p>***,再总结一下XHTML中的一些规范:</p><ul><li>· 因为是XML,所以为了表示这是一个HTML文档,必须有一个命名空间,其值为http://www.w3.org/1999/xhtml。</li> <li>· 因为是XML,所以MIME type不能是text/html了,text/xml、application/xml、application/xml+html都是比较好的选择。</li> <li>· 因为是XML,必须有根元素,根元素为<html>,即<html>的开始和结束标签不能省略了。</li> <li>· 因为是XML,所有元素只要有了开始标签,就不能没有结束标签,或者自闭合。</li> <li>· 因为是XML,所有元素都得严格遵守大小写,元素名称必须为小写。</li></ul> <p>因为是XML,文档变得严格了很多,也因为是XML,其可读性和规范性提高了不少。但最终,我们始终要在HTML的宽容性和XML的规范性之间找到***的平衡点,一味地追求极端始终是一个错误。<br />  </p><p><em>原文链接:http://www.cnblogs.com/GrayZhang/archive/2011/03/28/learning-html5-structure.html</em></p><p>【编辑推荐】</p> <ol> <li>Modernizr:为HTML 5和CSS3而生</li> <li>学习HTML 5十佳站点推荐</li> <li>技术大牛谈HTML 5设计原理</li> <li>HTML 5联手jQuery实现超酷图像灰度渐变效果</li> <li>HTML 5之表单新功能解析</li> </ol> <p> 标题名称:<a href="http://www.csdahua.cn/qtweb/news35/499785.html">HTML5标准学习入门之文档结构</a> <br> 文章路径:<a href="http://www.csdahua.cn/qtweb/news35/499785.html">http://www.csdahua.cn/qtweb/news35/499785.html</a> </p> <p> 网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等 </p> <p class="adpic"> <a href="https://www.cdcxhl.com/service/ad.html" target="_blank" class="ad">广告</a> <a href="" target="_blank" class="adimg"><img src=""></a> </p> <p class="copy"> 声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: <a href="http://www.csdahua.cn/" target="_blank">快上网</a> </p> </div> <div class="newsmorelb"> <p>成都快上网为您推荐相关内容</p> <ul> <li> <a href="/qtweb/news34/499784.html">给Linux安装Edge浏览器的指南(edgelinux)</a> </li><li> <a href="/qtweb/news33/499783.html">Redis实现累积登录天数统计(redis 累积登录天数)</a> </li><li> <a href="/qtweb/news32/499782.html">windows无法与设备或资源通信怎么弄?windows无法与设备或资源通信</a> </li><li> <a href="/qtweb/news31/499781.html">FlinkCDC里支持7.07版本吗?</a> </li><li> <a href="/qtweb/news30/499780.html">如何隐藏链接地址如何隐藏超链接,如何删除隐藏超链接</a> </li><li> <a href="/qtweb/news29/499779.html">独立高防服务器租用多少钱一个月</a> </li><li> <a href="/qtweb/news28/499778.html">Linux下安装DNS服务的步骤(linux下安装dns)</a> </li><li> <a href="/qtweb/news27/499777.html">“大规模网络攻击”攻陷多家乌克兰政府网站</a> </li><li> <a href="/qtweb/news26/499776.html">你什么时候退群了</a> </li> </ul> </div> </div> <div class="col-lg-3 noneb"> <div class="bkright" style="margin-top: 0"> <p><a href="https://www.cdcxhl.com/news/shop/">商城网站知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news19/130369.html">深入探讨云计算的前景</a> </li><li> <a class="text_overflow" href="/qtweb/news8/253158.html">创新互联Python教程:如何用python3代码玩小游戏?</a> </li><li> <a class="text_overflow" href="/qtweb/news49/236299.html">中国十大国产手机品牌是哪些?(泰国服务器租用快吗?泰国服务器租用有哪家IDC商提供?)</a> </li><li> <a class="text_overflow" href="/qtweb/news38/361588.html">打造高效人力资源管理的数据库设计(人力资源管理系统数据库设计)</a> </li><li> <a class="text_overflow" href="/qtweb/news27/233727.html">已知备案号,怎么查找对于的接入商?(如何查询备案接入)</a> </li><li> <a class="text_overflow" href="/qtweb/news4/182504.html">LinuxC编程中的方向键控制(linuxc方向键)</a> </li><li> <a class="text_overflow" href="/qtweb/news43/488943.html">深度揭秘Airbnb的跨洋大数据挑战及架构实战</a> </li><li> <a class="text_overflow" href="/qtweb/news23/153873.html">台式电脑怎么开机按哪个键</a> </li><li> <a class="text_overflow" href="/qtweb/news20/338170.html">Flex与Web应用的发展</a> </li><li> <a class="text_overflow" href="/qtweb/news30/174530.html">acc蜜罐怎么配?(主机被阻断-虚拟主机/数据库问题)</a> </li><li> <a class="text_overflow" href="/qtweb/news14/145114.html">称Redis设计为用户名称做有效解决方案(redis设计用户名)</a> </li><li> <a class="text_overflow" href="/qtweb/news44/287744.html">SQLServer重复数据删除的2个方案</a> </li><li> <a class="text_overflow" href="/qtweb/news2/187752.html">域名纠错系统有哪些类型</a> </li><li> <a class="text_overflow" href="/qtweb/news40/145140.html">oracle查询所有表的方法</a> </li><li> <a class="text_overflow" href="/qtweb/news18/519468.html">详解Oracle如何解锁用户的方法</a> </li> </ul> </div> <div class="bkright tag"> <p><a href="https://www.cdcxhl.com/hangye/" target="_blank">分类信息网</a></p> <ul> <li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/muwu/" target="_blank">木屋</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zufadianji/" target="_blank">发电机租赁</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/weixiufdj/" target="_blank">发电机维修</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/boligeduan/" target="_blank">玻璃隔断</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zhendongpan/" target="_blank">振动盘</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/putaojia/" target="_blank">葡萄架</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/caihui/" target="_blank">墙体彩绘</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/shachuang/" target="_blank">纱窗</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/qchs/" target="_blank">报废汽车回收</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/weilanhulan/" target="_blank">围栏护栏</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/lajitong/" target="_blank">垃圾桶</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/fadianjihs/" target="_blank">发电机回收</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/sqwhq/" target="_blank">社区文化墙</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/blgzd/" target="_blank">玻璃钢坐凳</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/chayisj/" target="_blank">茶艺设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/renzaowu/" target="_blank">人造雾</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="https://www.xwcx.net/select.html" target="_blank">四川成都托管服务器</a>    <a href="https://www.cdcxhl.com/qiye.html" target="_blank">企业网站建设</a>    <a href="http://m.cdxwcx.com/weixin.html" target="_blank">成都微信开发</a>    <a href="http://www.czfdjwx.com/" target="_blank">崇州威斯达宇</a>    <a href="http://www.wjzwz.com/" target="_blank">温江网站建设</a>    <a href="http://www.scdaying.com/" target="_blank">大英网站建设</a>    <a href="https://www.cdxwcx.com/jifang/yaan.html" target="_blank">雅安服务器托管</a>    <a href="http://www.cdymzj.com/" target="_blank">云主机</a>    <a href="http://www.cdlinhua.com/" target="_blank">成都商务茶叶销售</a>    <a href="http://www.msfdjwx.com/" target="_blank">眉山发电机维修</a>    <a href="http://www.gawzjs.com/" target="_blank">广安网站设计</a>    <a href="http://www.4006tel.net/yingxiao/" target="_blank">营销网站定位</a>    <a href="https://www.cdxwcx.com/tuiguang/" target="_blank">成都网站推广</a>    <a href="https://www.cdxwcx.com/city/leshan/" target="_blank">乐山做网站</a>    <a href="https://www.xwcx.net/jigui.html" target="_blank">成都服务器机柜租用</a>    <a href="http://chengdu.cdcxhl.cn/seo/ " target="_blank">成都网站推广</a>    <a href="http://www.lbtjx.cn/" target="_blank">力比特机械</a>    <a href="https://www.cdcxhl.com/sosuo.html" target="_blank">关键词排名</a>    <a href="https://www.cdcxhl.cn/ " target="_blank">香港空间腾讯云</a>    <a href="http://www.hzlinhua.com/" target="_blank">成都茶叶销售</a>     </div> </div> <footer> <div class="carousel-inner footjz"> <div class="container"> <i class="icon iconfont zbw"></i> 高品质定制 <i class="icon iconfont"></i> 跨终端自动兼容 <i class="icon iconfont"></i> 节约开发成本 <i class="icon iconfont"></i> 开发周期短 <i class="icon iconfont"></i> 一体化服务 <button type="button" class="btn btn-default btn-lg" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 立即开始2800定制网站建设</button> <button type="button" class="btn btn-default btn-xs" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 2800定制网站建设</button> </div> </div> <div class="carousel-inner bqsy"> <div class="container"> <div class="lxfs"> <h4 class="yutelnone">028-86922220 13518219792</h4> <h4 class="yutelblock"><a href="tel:02886922220">028-86922220</a> <a href="tel:13518219792">13518219792</a></h4> <a class="btn btn-default" href="tencent://message/?uin=532337155&Site=&Menu=yes" role="button">网站建设<span>QQ</span>:532337155</a> <a class="btn btn-default" href="tencent://message/?uin=631063699&Site=&Menu=yes" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=532337155&version=1&src_type=web&web_src=oicqzone.com" role="button">网站制作<span>QQ</span>:532337155</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=631063699&version=1&src_type=web&web_src=oicqzone.com" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn-default nonea" href="tencent://message/?uin=1683211881&Site=&Menu=yes" role="button">售后QQ:1683211881</a> <div class="dz">成都快上网专注: <a href="http://www.csdahua.cn/" target="_blank">网站优化</a> <a href="http://www.csdahua.cn/" target="_blank">网络推广</a> <a href="http://www.csdahua.cn/" target="_blank">网站建设</a> <address>地址:成都太升南路288号锦天国际A幢10楼</address> </div> </div> <div class="bzdh dz"><img src="https://www.cdcxhl.com/imges/bottom_logo.png" alt="创新互联"> <p><a href="https://www.cdcxhl.com/menu.html" target="_blank">成都创新互联科技有限公司</a><br> Tel:028-86922220(7x24h)</p></div> </div> </div> </footer> </body> </html> <script> $.getJSON ("../../qtwebpic.txt", function (data) { var jsonContent = { "featured":data } var random = jsonContent.featured[Math.floor(Math.random() * jsonContent.featured.length)]; $(".adpic .adimg").attr("href",random.link) $(".adpic img").attr("src",random.pic); }) </script>