首页 > 编程 > HTML > 正文

HTML(5) 样式指南和代码约定

2020-03-24 17:19:55
字体:
来源:转载
供稿:网友

请始终定义图像尺寸。这样做会减少闪烁,因为浏览器会在图像加载之前为图像预留空间。

 img src= html5.gif alt= HTML5 >

但是精简空格更易阅读,But space-less is easier to read, and groups entities better together:

 link rel= stylesheet href= styles.css 

请勿使用没有必要的空行和缩进。没有必要在短的和相关项目之间使用空行,也没有必要缩进每个元素:

不必要:

 body  h1 Famous Cities /1  h2 Tokyo /h2  Tokyo is the capital of Japan, the center of the Greater Tokyo Area, and the most populous metropolitan area in the world. It is the seat of the Japanese government and the Imperial Palace, and the home of the Japanese Imperial Family. /body 

更好:

 body  h1 Famous Cities /1  h2 Tokyo /h2 Tokyo is the capital of Japan, the center of the Greater Tokyo Area,and the most populous metropolitan area in the world.It is the seat of the Japanese government and the Imperial Palace,and the home of the Japanese Imperial Family. /body 

表格示例:

 table  th Name /th  th Description /th  td A /td  td Description of A /td  td B /td  td Description of B /td  /table 

列表示例:

 li LondonA /li  li Paris /li  li Tokyo /li  /ol 

为了确保恰当的解释,以及正确的搜索引擎索引,在文档中对语言和字符编码的定义越早越好:

 !DOCTYPE html  html lang= en-US  head  meta charset= UTF-8  title HTML5 Syntax and Coding Style /title  /head 

!-- This is a long comment example. This is a long comment example. This is a long comment example. This is a long comment example. This is a long comment example. This is a long comment example.

注释更易观察,如果它们被缩进两个空格的话。


如果您从对大小写不敏感的服务器转到一台对大小写敏感的服务器上,这些小错误将破坏您的网站。

为了避免这些问题,请始终使用小写文件名(如果可以的话)。

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表