十二天学会DIV+CSS之第六天

第六天 XHTML代码规范

在开始正式内容制作之前,我们必须先了解一下web标准有关代码的规范。
了解这些规范可以帮助你少走弯路,尽快通过代码校验。使我们的代码有一个统一、唯一的标准!

1.所有的标记都必须要有一个相应的结束标记
以前在HTML中,你可以打开许多标签,例如

  • 而不一定写对应的

  • 来关闭它们。但在XHTML中这是不合法的。XHTML要求有严谨的结构,所有标签必须关闭。如果是单独不成对的标签,在标签最后加一个"/"来关闭它。例如:

    网页设计师

    2.所有标签的元素和属性的名字都必须使用小写
    与HTML不一样,XHTML对大小写是敏感的,和<title>是不同的标签。XHTML要求所有的标签和属性的名字都必须使用小写。例如:<body>必须写成<body> 。大小写夹杂也是不被认可的,通常dreamweaver自动生成的属性名字"onMouseOver"也必须修改成"onmouseover"。</p> <p>3.所有的XML标记都必须合理嵌套<br /> 同样因为XHTML要求有严谨的结构,因此所有的嵌套都必须按顺序,以前我们这样写的代码:</p> <p><b></p> <p></b><br /> 必须修改为:</p> <p><b></b></p> <p>就是说,一层一层的嵌套必须是严格对称。</p> <p>4.所有的属性必须用引号""括起来<br /> 在HTML中,你可以不需要给属性值加引号,但是在XHTML中,它们必须被加引号。例如:<br /> <height=80><br /> 必须修改为:<br /> <height="80"><br /> 特殊情况,你需要在属性值里使用双引号,你可以用",单引号可以使用',例如:<br /> <alt="say'hello'"></p> <p>5.把所有<和&特殊符号用编码表示 任何小于号(<),不是标签的一部分,都必须被编码为& l t ; 任何大于号(>),不是标签的一部分,都必须被编码为& g t ;<br /> 任何与号(&),不是实体的一部分的,都必须被编码为& a m p;<br /> 注:以上字符之间无空格。</p> <p>6.给所有属性赋一个值<br /> XHTML规定所有属性都必须有一个值,没有值的就重复本身。例如:</p> <td nowrap> <input type="checkbox" name="shirt" value="medium" checked> 必须修改为:</p> <td nowrap="nowrap"> <input type="checkbox" name="shirt" value="medium" checked="checked"></p> <p>7.不要在注释内容中使“--”<br /> “--”只能发生在XHTML注释的开头和结束,也就是说,在内容中它们不再有效。<br /> 例如下面的代码是无效的:<br /> <!--这里是注释-----------这里是注释--><br /> 用等号或者空格替换内部的虚线。<br /> <!--这里是注释============这里是注释--><br /> 以上这些规范有的看上去比较奇怪,但这一切都是为了使我们的代码有一个统一、唯一的标准!<br /> 以便于将来的数据再利用!!</p> </div> <div class="single-copyright"> <div>版权声明:</div><div>作者:肖铭</div><div>链接:http://www.zhouyuming.com/archives/892</div><div>文章版权归作者所有,未经允许请勿转载。</div> </div> <div class="post-end-dividing"> THE END </div> <app-single-btns id="app-single-btns"></app-single-btns> <div class="post-page-card"> <div class="card-item "> <div class="card-item-img" style="background-image:url(http://www.zhouyuming.com/wp-content/themes/CoreNext/static/img/slt2.png)"> <a href="http://www.zhouyuming.com/archives/891"> <div>十二天学会DIV+CSS之第五天</div> <div><<上一篇</div> </a> </div> </div><div class="card-item "> <div class="card-item-img" style="background-image:url(http://www.zhouyuming.com/wp-content/themes/CoreNext/static/img/slt2.png)"> <a href="http://www.zhouyuming.com/archives/893"> <div>十二天学会DIV+CSS之第七天</div> <div>下一篇>></div> </a> </div> </div> </div> </div> <div class="related-articles"> <div class="related-title"> 相关推荐 </div> <div class="related-articles-list" ref=""><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/1550" target="_blank">Adobe 2024 Patcher 1.85 Adobe for Mac 2024通用补丁</a> </div><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/1329" target="_blank">告诉你如何彻底卸载karabiner elements,让你变得不再头疼</a> </div><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/1328" target="_blank">让windows 使用苹果magic trackpad 2 妙控触摸板</a> </div><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/1323" target="_blank">利用Mac OS X内置工具生成强密码</a> </div><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/1321" target="_blank">我个人正在使用的剪贴板软件,Maccy,小巧快速!</a> </div><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/1319" target="_blank">我在正在使用的 Mac 看图软件,速度很快,免费使用!</a> </div><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/1127" target="_blank">MAC的所有快捷键</a> </div><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/1124" target="_blank">仙剑奇侠传5 mac版</a> </div><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/922" target="_blank">单个日志页面地址已完全静态化</a> </div><div class="related-articles-post-item"> <span class="li-item"></span> <a href="http://www.zhouyuming.com/archives/919" target="_blank">[测试FCKeditor]新产品上线,雅虎奥运生活服务!</a> </div></div> </div> <app-comment id="app-comment"></app-comment> </div> <aside> <div class="aside-box widget_recent_entries"> <h2 class="widget-title widget-title-mac">近期文章</h2> <ul> <li> <a href="http://www.zhouyuming.com/archives/1466">windows最强下载工具idm6.4.2最新下载及免费使用办法</a> </li> <li> <a href="http://www.zhouyuming.com/archives/1338">WinRAR 6.24简体中文商业版 – 最新发布 | 高效的压缩工具</a> </li> <li> <a href="http://www.zhouyuming.com/archives/1650">Windows 10 22H2 19045.3693 微软桌面操作系统</a> </li> <li> <a href="http://www.zhouyuming.com/archives/1645">PixPin – 高效截图工具:贴图、截长图、截动图、OCR 文字识别 – Windows版</a> </li> <li> <a href="http://www.zhouyuming.com/archives/1581">11月最新百度网盘文件下载指南 | 一站式解决方案</a> </li> </ul> </div><div class="aside-box widget_search"><form role="search" method="get" id="searchform" class="searchform" action="http://www.zhouyuming.com/"> <div> <label class="screen-reader-text" for="s">搜索:</label> <input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="搜索" /> </div> </form></div><div class="aside-box widget_core_next_post_list_widget"><h2 class="widget-title widget-title-mac">文章列表</h2> <div class="core-next-widget-post-list"><div class="widget-post-item widget-post-item-first"> <span class="widget-post-item-index">1</span> <a href="http://www.zhouyuming.com/archives/394" target="_blank"><img src="http://www.zhouyuming.com/wp-content/themes/CoreNext/static/img/slt2.png" alt="thumbnail"></a> <div class="widget-post-title-warp"> <a href="http://www.zhouyuming.com/archives/394" target="_blank">最后的记录二</a> </div> </div><div class="widget-post-item"> <span class="widget-post-item-index">2</span> <div class="post-thumbnail"> <a href="http://www.zhouyuming.com/archives/1048" target="_blank"><img src="http://www.zhouyuming.com/wp-content/themes/CoreNext/static/img/slt2.png" alt="thumbnail"></a> </div> <div class="post-main"> <a href="http://www.zhouyuming.com/archives/1048" target="_blank">【小说直播】我竟然梦到了初中女同桌十六</a> <div class="widget-post-info"><a href="http://www.zhouyuming.com/archives/category/riji" target="_blank">堂主日志</a></div> </div> </div><div class="widget-post-item"> <span class="widget-post-item-index">3</span> <div class="post-thumbnail"> <a href="http://www.zhouyuming.com/archives/166" target="_blank"><img src="http://www.zhouyuming.com/wp-content/themes/CoreNext/static/img/slt2.png" alt="thumbnail"></a> </div> <div class="post-main"> <a href="http://www.zhouyuming.com/archives/166" target="_blank">爱在桂林子页设计之五</a> <div class="widget-post-info"><a href="http://www.zhouyuming.com/archives/category/zuopin" target="_blank">我的作品</a></div> </div> </div><div class="widget-post-item"> <span class="widget-post-item-index">4</span> <div class="post-thumbnail"> <a href="http://www.zhouyuming.com/archives/674" target="_blank"><img src="http://www.zhouyuming.com/wp-content/themes/CoreNext/static/img/slt2.png" alt="thumbnail"></a> </div> <div class="post-main"> <a href="http://www.zhouyuming.com/archives/674" target="_blank">在阿里巴巴培训的日子(三)[超大百张组图]</a> <div class="widget-post-info"><a href="http://www.zhouyuming.com/archives/category/riji" target="_blank">堂主日志</a></div> </div> </div><div class="widget-post-item"> <span class="widget-post-item-index">5</span> <div class="post-thumbnail"> <a href="http://www.zhouyuming.com/archives/658" target="_blank"><img src="http://www.zhouyuming.com/wp-content/themes/CoreNext/static/img/slt2.png" alt="thumbnail"></a> </div> <div class="post-main"> <a href="http://www.zhouyuming.com/archives/658" target="_blank">Lblog批量删除垃圾引用的方法</a> <div class="widget-post-info"><a href="http://www.zhouyuming.com/archives/category/macsoft" target="_blank">Mac软件</a></div> </div> </div></div></div> </aside> </main> <div class="footer-wave"> <svg class="editorial" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none"> <defs> <path id="core-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"></path> </defs> <g class="parallax"> <use xlink:href="#core-wave" x="50" y="0" fill="#6a7277"></use> <use xlink:href="#core-wave" x="50" y="3" fill="#3f4549"></use> <use xlink:href="#core-wave" x="50" y="6" fill="#22292d"></use> </g> </svg> </div> <style> .core-footer { margin-top: 0!important; } </style> <div class="core-footer"> <div class="footer-main container"> <div class="footer-left"> <div> </div> <div> Copyright © 2024 芸轩草堂 CoreNext Powered by WordPress </div> <div class="icp-warp" id="icp-warp"> <div> <img src="http://www.zhouyuming.com/wp-content/themes/CoreNext/static/img/icon/icp.svg" width="24"><a href="https://beian.miit.gov.cn/" target="_blank">冀ICP备09025186号-1</a> </div> </div> </div> <div class="footer-right"> </div> </div> </div> <div class="phone-nav"> </div></div> </body> <script>console.log("\n %c 本站由WPOPT插件优化 %c www.lovestu.com/wpopt.html", "color:#fff;background:#3983e2;padding:5px 0;", "color:#eee;background:#f0f0f0;padding:5px 10px;");</script><style></style><style> :root { --box-border-radius: 5px; --theme-color: #0C6FF8; --a-hover-color: #0C6FF8; } .el-pagination.is-background .el-pager li:not(.disabled).active { background-color: #0C6FF8; } .el-pagination.is-background .el-pager li:not(.disabled):hover { color:#0C6FF8; } ::selection { background-color: #07B75C; } .el-button--primary{ background-color: #0C6FF8; border-color: #0C6FF8; } .el-button--primary:focus, .el-button--primary:hover{ background-color: #0C6FF8; border-color: #0C6FF8; opacity: .8; } .el-button:focus, .el-button:hover{ opacity: .8; } </style> <style> .content-warp img:not(.not-shadow){box-shadow: 0 0 5px 0 rgba(0, 0, 0, .1);} </style> <style> @font-face { font-family: DingTalkJinBuTi-Regular; font-display: swap; src: url(https://puhuiti.oss-cn-hangzhou.aliyuncs.com/DingTalkJinBuTi/DingTalkJinBuTi-Regular/DingTalkJinBuTi-Regular.eot) format('embedded-opentype'), url(https://puhuiti.oss-cn-hangzhou.aliyuncs.com/DingTalkJinBuTi/DingTalkJinBuTi-Regular/DingTalkJinBuTi-Regular.otf) format('opentype'), url(https://puhuiti.oss-cn-hangzhou.aliyuncs.com/DingTalkJinBuTi/DingTalkJinBuTi-Regular/DingTalkJinBuTi-Regular.ttf) format('TrueType'), url(https://puhuiti.oss-cn-hangzhou.aliyuncs.com/DingTalkJinBuTi/DingTalkJinBuTi-Regular/DingTalkJinBuTi-Regular.woff) format('woff'), url(https://puhuiti.oss-cn-hangzhou.aliyuncs.com/DingTalkJinBuTi/DingTalkJinBuTi-Regular/DingTalkJinBuTi-Regular.woff2) format('woff2'); } body { font-family: 'DingTalkJinBuTi-Regular', system-ui; } </style> <script type="text/javascript" src="http://www.zhouyuming.com/wp-content/themes/CoreNext/static/js/global.min.js?ver=59" id="core_next_global-js"></script> <script type="text/javascript" src="http://www.zhouyuming.com/wp-content/themes/CoreNext/static/js/single-page.min.js?ver=59" id="core_next_single_page-js"></script> <script type="text/javascript" src="http://www.zhouyuming.com/wp-content/themes/CoreNext/static/js/html2canvas.min.js?ver=59" id="html2canvas-js"></script> </html>