Front-end HTML specification

WBOY
Release: 2016-09-06 08:43:45
Original
893 people have browsed it

HTML规范 - 整体结构

  • 文件应以“”首行顶格开始,推荐使用“”。
  • 必须申明文档的编码charset,且与文件本身编码保持一致,推荐使用UTF-8编码。
  • 根据页面内容和需求填写适当的keywords和description。
  • 页面title是极为重要的不可缺少的一项。




html规范








Copy after login

结构顺序和视觉顺序基本保持一致

  • 按照从上至下、从左到右的视觉顺序书写HTML结构。
  • 有时候为了便于搜索引擎抓取,我们也会将重要内容在HTML结构顺序上提前。
  • 用div代替table布局,可以使HTML更具灵活性,也方便利用CSS控制。
  • table不建议用于布局,但表现具有明显表格形式的数据,table还是首选。

结构、表现、行为三者分离,避免内联

  • 使用link将css文件引入,并置于head中。
  • 使用script将js文件引入,并置于body底部。

保持良好的简洁的树形结构

  • 每一个块级元素都另起一行,每一行都使用Tab缩进对齐(head和body的子元素不需要缩进)。删除冗余的行尾的空格。
  • 使用4个空格代替1个Tab(大多数编辑器中可设置)。
  • 对于内容较为简单的表格,建议将tr写成单行。
  • 你也可以在大的模块之间用空行隔开,使模块更清晰。


热门标签

...

最热TOP5

更多»
...


Copy after login

另外,请做到以下几点

  • 结构上如果可以并列书写,就不要嵌套。如果可以写成

    那么就不要写成

  • 如果结构已经可以满足视觉和语义的要求,那么就不要有额外的冗余的结构。 比如

    已经能满足要求,那么就不要再写成

  • 一个标签上引用的className不要过多,越少越好。比如不要出现这种情况:

  • 对于一个语义化的内部标签,应尽量避免使用className。比如在这样一个列表中,li标签中的itm应去除:

HTML规范 - 代码格式

说明文案的注释方法

采用类似标签闭合的写法,与HTML统一格式;注释文案两头空格,与CSS注释统一格式。

  • 开始注释:(文案两头空格)。
  • 结束注释:(文案前加“/”符号,类似标签的闭合)。
  • 允许只有开始注释!




Copy after login

代码本身的注释方法

单行代码的注释也保持同行,两端空格;多行代码的注释起始和结尾都另起一行并左缩进对齐。


Copy after login

严格的嵌套

  • 尽可能以最严格的xhtml strict标准来嵌套,比如内联元素不能包含块级元素等等。
  • 正确闭合标签且必须闭合。

严格的属性

  • 属性和值全部小写,每个属性都必须有一个值,每个值必须加双引号。
  • 没有值的属性必须使用自己的名称做为值(checked、disabled、readonly、selected等等)。
  • 可以省略style标签和script标签的type属性。

常用的标签

常见标签表

标签

标签  语义 嵌套常见错误 常用属性(加粗的为不可缺少的或建议的)
超链接/锚 a不可嵌套a href,name,title,rel,target

换行    
按钮 不可嵌套表单元素 type,disabled
定义列表中的定义(描述内容) 只能以dl为父容器,对应一个dt  
文本删除    
Block level container
Definition list Only dt and dd can be nested
Definition terms in definition list Only dl can be used as the parent container, corresponding to multiple dd
Emphasis text
Form action,target,method,name

Title From h1 to h6, block-level elements cannot be nested
Embed a webpage frameborder,width,height,src,scrolling,name
Image alt,src,width,height
Various form controls type,name,value,checked,disabled,maxlength,readonly,accesskey
The tag defines the annotation for the input element for
  • List items Only ul or ol can be the parent container
    Quote style or icon No elements can be nested type,rel,href
    Documentation information Only for head content,http-equiv,name
      Ordered List Only li can be nested
      An option in select Only for select value,selected,disabled

      Paragraph Block-level elements cannot be nested
      Quote script No elements can be nested type,src
      List box or drop down box Only option or optgroup can be nested name,disabled,multiple
      Inline container
      Emphasis text
      Quote style No elements can be nested type,media
      subscript
      superscript
      Form Only table elements can be nested width,align,background,cellpadding,cellspacing,summary,border
      Table body Only for table
      Cells in tables Only for tr colspan,rowspan
      Multi-line text input control name,accesskey,disabled,readonly,rows,cols
      Table footer Only for table
      Title cells in tables Only for tr colspan,rowspan
      Table header Only for table
      Document Title Only for head
      Table rows Nested in table or thead, tbody, tfoot
        Unordered list Only li can be nested

         

        HTML规范 - 内容语义

        加强“资源型”内容的可访问性和可用性

        在资源型的内容上加入描述文案,比如给img添加alt属性,在audio内加入文案和链接等等。

        加强“不可见”内容的可访问性

        背景图上的文字应该同时写在html中,并使用css使其不可见,有利于搜索引擎抓取你的内容,也可以在css失效的情况下看到内容。

        适当使用实体

        常用HTML字符实体(建议使用实体):
        字符 名称 实体名 实体数
        " 双引号 " "
        & &符 & &
        < 左尖括号(小于号) < <
        > 右尖括号(大于号) > >
          空格  
          中文全角空格    
         
        Copy after login
        Copy after login
        Copy after login
        常用特殊字符实体(不建议使用实体):
        字符 名称 实体名 实体数
        ¥ ¥ ¥
        ¦ 断竖线 ¦ ¦
        © 版权 © ©
        ® 注册商标R ® ®
        商标TM
        · 间隔符 · ·
        « 左双尖括号 « «
        » 右双尖括号 » »
        ° ° °
        × × ×
        ÷ ÷ ÷
        千分比
         
        Copy after login
        Copy after login
        Copy after login
         
        Copy after login
        Copy after login
        Copy after login
        Related labels:
        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
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!