Home > Web Front-end > HTML Tutorial > Web front-end development specification document (transferred)_html/css_WEB-ITnose

Web front-end development specification document (transferred)_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:34:47
Original
1131 people have browsed it

本文处之:http://www.w3cfuns.com/blog-1-534.html

规范目的
为提高团队协作效率, 便于后台人员添加功能及前端后期优化维护, 输出高质量的文档, 特制订此文档. 本规范文档一经确认, 前端开发人员必须按本文档规范进行前台页面开发. 本文档如有不对或者不合适的地方请及时提出, 经讨论决定后方可更改.


基本准则
符合web标准, 语义化html, 结构表现行为分离, 兼容性优良. 页面性能方面, 代码要求简洁明了有序, 尽可能的减小服务器负载, 保证最快的解析速度.


文件规范
1. html, css, js, images文件均归档至<系统开发规范>约定的目录中;
2. html文件命名: 英文命名, 后缀.htm. 同时将对应界面稿放于同目录中, 若界面稿命名为中文, 请重命名与html文件同名, 以方便后端添加功能时查找对应页面;
3. css文件命名: 英文命名, 后缀.css. 共用base.css, 首页index.css, 其他页面依实际模块需求命名;
4. Js文件命名: 英文命名, 后缀.js. 共用common.js, 其他依实际模块需求命名.

html书写规范
1. 文档类型声明及编码: 统一为html5声明类型; 编码统一为, 书写时利用IDE实现层次分明的缩进;
2. 非特殊情况下样式文件必须外链至...之间;非特殊情况下JavaScript文件必须外链至页面底部;
3. 引入样式文件或JavaScript文件时, 须略去默认类型声明, 写法如下:




4. 引入JS库文件, 文件名须包含库名称及版本号及是否为压缩版, 比如jquery-1.4.1.min.js; 引入插件, 文件名格式为库名称+插件名称, 比如jQuery.cookie.js;

5. 所有编码均遵循xhtml标准, 标签 & 属性 & 属性命名 必须由小写字母及下划线数字组成, 且所有标签必须闭合, 包括 br (
), hr(


)等; 属性值必须用双引号包括;

6. 充分利用无兼容性问题的html自身标签, 比如span, em, strong, optgroup, label,等等; 需要为html元素添加自定义属性的时候, 首先要考虑下有没有默认的已有的合适标签去设置, 如果没有, 可以使用须以"data-"为前缀来添加自定义属性,避免使用"data:"等其他命名方式;

7. 语义化html, 如 标题根据重要性用h*(同一页面只能有一个h1), 段落标记用p, 列表用ul, 内联元素中不可嵌套块级元素;

8. 尽可能减少div嵌套, 如
欢迎访问XXX, 您的用户名是
用户名
完全可以用以下代码替代:

欢迎访问XXX, 您的用户名是用户名

;

9. 书写链接地址时, 必须避免重定向,例如:href="http://itaolun.com/", 即须在URL地址后面加上“/”;

10. 在页面中尽量避免使用style属性,即style="…";

11. 必须为含有描述性表单元素(input, textarea)添加label, 如

姓名:

须写成:



12. 能以背景形式呈现的图片, 尽量写入css样式中;

13. 重要图片必须加上alt属性; 给重要的元素和截断的元素加上title;

14. 给区块代码及重要功能(比如循环)加上注释, 方便后台添加功能;

15. 特殊符号使用: 尽可能使用代码替代: 比如 <(<) & >(>) & 空格( ) & »(») 等等;

16. 书写页面过程中, 请考虑向后扩展性;

17. class & id 参见 css书写规范.


css书写规范
1. 编码统一为utf-8;

2. 协作开发及分工: i会根据各个模块, 同时根据页面相似程序, 事先写好大体框架文件, 分配给前端人员实现内部结构&表现&行为;  共用css文件base.css由i书写, 协作开发过程中, 每个页面请务必都要引入, 此文件包含reset及头部底部样式, 此文件不可随意修改;

3. class与id的使用: id是唯一的并是父级的, class是可以重复的并是子级的, 所以id仅使用在大的模块上, class可用在重复使用率高及子级中; id原则上都是由我分发框架文件时命名的, 为JavaScript预留钩子的除外;

4. 为JavaScript预留钩子的命名, 请以 js_ 起始, 比如: js_hide, js_show;

5. class与id命名: 大的框架命名比如header/footer/wrapper/left/right之类的在2中由i统一命名.其他样式名称由 小写英文 & 数字 & _ 来组合命名, 如i_comment, fontred, width200; 避免使用中文拼音, 尽量使用简易的单词组合; 总之, 命名要语义化, 简明化.

6. 规避class与id命名(此条重要, 若有不明白请及时与i沟通):
    a) 通过从属写法规避, 示例见d;
    b)取父级元素id/class命名部分命名, 示例见d;
    c)重复使用率高的命名, 请以自己代号加下划线起始, 比如i_clear;
    d)a,b两条, 适用于在2中已建好框架的页面, 如, 要在2中已建好框架的页面代码中加入新的div元素,

按a命名法则: ,
样式写法:  #mainnav  .firstnav{.......}

按b命名法则: ,
Style writing: .main_firstnav{.....}

7. The order of writing css attributes is recommended to be followed: Layout positioning attribute-->Self attribute-->Text attribute -->Other attributes. This article can be written according to your own habits, but try to ensure that similar attributes are written together. Attribute enumeration: Layout positioning attributes mainly include: display & list-style & position (corresponding top, right, bottom, left ) & float & clear & visibility & overflow; Its own properties mainly include: width & height & margin & padding & border & background; Text properties mainly include: color & font & text-decoration & text-align & vertical-align & white- space & other& content; The attributes I listed are only the most commonly used ones, and do not represent all;

8. Before writing code, consider and improve the rate of style reuse;

9. Make full use of HTML's own attributes and style inheritance principles to reduce the amount of code, for example:
  • Here is the title list2010-09- 15
    define
    ul.list li{position:relative} ul.list li span{position:absolute; right:0}
    to display the date on the right

    10. The Chinese font name in the style sheet must be converted into unicode code to avoid garbled characters when encoding errors;

    11. Please use sprite technology as much as possible for background images to reduce http requests, taking into account Multi-person collaborative development, sprites are made according to modules;

    12. When using table tags (try to avoid using table tags), please do not use table attributes such as width/height/cellspacing/cellpadding to directly define the performance. Try to Use the table's own private attributes to separate structure and performance, such as thead, tr, th, td, tbody, tfoot, colgroup, scope; (css control method of cellspaing and cellpadding: table{border:0;margin:0;border-collapse :collapse;} table th, table td{padding:0;}, I will initialize the table style in the base.css file)

    13. Avoid using Compatible with ie8;

    14. When using png pictures to make pictures, the picture format is required to be png-8 format. If png-8 really affects the picture quality or half of it Transparency effect, please define the background separately for ie6:

    _background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (sizingMethod=crop, src='img/bg.png');

    15. Avoid the use of compatibility attributes, such as text-shadow || CSS3 related attributes;

    16. Reduce the use of attributes that affect performance, such as position:absolute || float;

    17. Comments must be added for large block styles, and appropriate comments for small blocks;

    18. Code indentation and format: It is recommended to write in a single line, according to your own habits, and I will handle it in a unified manner for later optimization;


    JavaScript writing specifications

    1. The file encoding is unified to utf-8, and after the writing process, there must be a semicolon at the end of each line of code; in principle, all functions are developed natively according to the needs of the XXX project. Avoid code pollution caused by code downloaded from the Internet (redundant code || conflicts with existing code || ...);

    2. Library introduction: In principle, only the jQuery library is introduced. If you need to introduce the Third-party libraries must be discussed and decided with other members of the team;

    3. Variable naming: camel case naming. Native JavaScript variables are required to be pure English letters, and the first letter must be lowercase, such as iTaoLun;

    jQuery Variables require the first character to be '_', and other rules are the same as native JavaScript, such as: _iTaoLun;

    In addition, variables are required to be declared in a centralized manner and avoid global variables.

    4. Class naming: first letter Uppercase, camel case naming. Such as ITaoLun;

    5. Function naming: lowercase camel case naming. Such as iTaoLun();

    6. Semantic naming, use English words or Its abbreviation;

    7. Try to avoid using methods or attributes that have compatibility and consume resources, such as eval_r() & innerText;

    8. In later optimization, JavaScript non-comment Chinese characters Must be converted to unicode encoding to avoid garbled display when encoding errors occur;

    9. The code structure is clear, add appropriate comments. Improve function reuse rate;

    10. Pay attention to separation from html, reduce Small reflow, focus on performance.


    Image specifications

    1. All page element pictures are placed in the img folder, and test pictures are placed in the img/demoimg folder;

    2. The image format is limited to gif || png || jpg;

    3. All names should be a combination of lowercase English letters || numbers || _, which must not contain Chinese characters || spaces || Special characters; try to use easy-to-understand vocabulary to facilitate understanding by other team members; in addition, the name is divided into two parts, the first and last parts, separated by underscores, such as ad_left01.gif || btn_submit.gif;

    4. While ensuring visual Choose the smallest image format and image quality to reduce loading time;

    5. Try to avoid using translucent png images (if used, please refer to the relevant instructions of the css specification);

    6. Use css sprite technology to focus on small background images or icons to reduce page http requests, but please be sure to draw reference lines in the corresponding sprite psd source image and save it to the img directory.


    Annotation specifications

    1. HTML comments: Comment format , '--' can only be used at the beginning and end of the comment, and cannot be placed in the comment text area;

    2. css comment: Comment format;

    3. JavaScript comments, single-line comments use '//This is a single-line comment', multi-line comments use;


    Development and testing tool conventions

    It is recommended to use Aptana || Dw || Vim, you can also choose according to your own preferences, but you must follow the following principles:

    1. Do not use the IDE's view mode to 'draw' code;

    2 . Do not use IDE to generate related function codes, such as some functional js built into Dw;

    3. Coding must be formatted, such as indentation;

    Testing tools: only FireFox & IE6 are tested in early development & IE7 & IE8, add Opera & Chrome & Safari during later optimization;
    Recommended test order: FireFox-->IE7-->IE8-->IE6-->Opera-->Chrome-- >Safari, it is recommended to install firebug and IE Tab Plus plug-ins.


    Other specifications

    1. During the development process, complete the page strictly according to the division of labor to improve the css reuse rate and avoid duplication Development;
    2. Reduce redundant code and write code that everyone can understand. Being concise and easy to understand is a virtue. Think about users and think about the server.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template