好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

HTML最佳实践_html/css_WEB-ITnose

HTML

DOCTYPE 头部开始

Bad:

   ...  

Good:

    ...  

不要用旧的 DOCTYPE

Bad:

  

Good:

  

不要用 XML 声明

Bad:

   

Good:

  

最好不要用字符引用

Bad:

Copyright © 2014 W3C ®

Good:

Copyright © 2014 W3C ®

    ###Escape &,  , ", and ' 可以用字符引用 

Bad:

The "&" character

Good:

The "&" character

Use named character references for control or invisible characters

Bad:

This book can read in 1 hour.

Good:

This book can read in 1 hour.

注释的内容两边留个空格

Bad:

  

Good:

  

不要忽略闭合标签

Bad:

        ... 

Good:

        ...     

不要搞混空元素的格式

Bad:

   

Good:

   

在标签里面和属性值里不要留空格

Bad:

HTML Best Practices

Good:

HTML Best Practices

不要搞混大小写

Bad:

General 

Good:

General 

不要混用引号标记

Bad:

  

Good:

  

Don't separate attributes with two or more white spaces

属性之间不要用两个空格隔开

Bad:

  

Good:

  

省略布尔属性的值

Bad:

 

Good:

 

省略命名空间

Bad:

   ...  

Good:

   ...  

不要用 xml 属性

Bad:

 ...  

Good:

 ...  

不要搞混 data-*,Microdata,RDFa Lite 属性和通用的属性

Bad:

  

Good:

  

更强的原生语义

Bad:

   ...   

Good:

   ...   

根元素

添加语言属性

Bad:

  

Good:

  

保持语言属性值尽可能的短

Bad

  

Good:

  

文档的元数据

添加 title 元素

Bad:

      

Good:

       HTML Best Practices   

指定微链接资源的 MIME 类型

Bad:

 

Good:

 

不要链接到 favicon.ico

Bad:

 

Good:

把 favicon.ico 放在根目录 

添加 title 属性到 备用样式表

Bad:

 

Good:

 

给文档指定字符编码

Bad:

    HTML Best Practices   

Good:

       HTML Best Practices   

不要用旧的字符编码格式

Bad:

  

Good:

  

首先就要指定字符编码

Bad:

         ...  

Good:

         ...  

使用 utf-8 格式

Bad:

  

Good:

  

css 的 type 属性不用写

Bad:

   ...  

Good:

   ...  

不要注释 style 元素的内容

Bad:

    

Good:

   ...  

不要搞混 css 和 js 标签

Bad:

     

Good:

     

Also good:

     

添加 body 标签

Bad:

        ...     ...  

Good:

        ...          ...     

忘了 hgroup 元素吧

Bad:

   

HTML Best Practices

For writing maintainable and scalable HTML documents.

Good:

HTML Best Practices

For writing maintainable and scalable HTML documents.

仅仅当在联系信息的时候用 address 元素

Bad:

No rights reserved.  

Good:

Contact: Kyo Nagashima  

pre 元素不要在新的一行开始写

Bad:

<!DOCTYPE html> 

Good:

<!DOCTYPE html> 

在引号元素里面使用 appropriate 元素

Bad:

 For writing maintainable and scalable HTML documents.  

Good:

   

For writing maintainable and scalable HTML documents.

不要直接包含属性在 blockquote 元素里

Bad:

   

For writing maintainable and scalable HTML documents.

— HTML Best Practices

Good:

   

For writing maintainable and scalable HTML documents.

— HTML Best Practices

Also good (recommended by WHATWG):

        

For writing maintainable and scalable HTML documents.

— HTML Best Practices

Also good too (recommended by W3C):

   

For writing maintainable and scalable HTML documents.

— HTML Best Practices

每行只写一个列表项目

Bad:

    General  The root Element  Sections ...  

Good:

    General    The root Element    Sections   ...  

给 ol 元素用上 type 属性

Bad:

        .toc {      list-style-type: upper-roman;    }             General      The root Element      Sections     ...     

Good:

         General      The root Element      Sections     ...     

把 figcaption 元素放在 figure 元素里的开头或结尾

Bad:

       “HTML Best Practices” Cover Art      

Good:

          “HTML Best Practices” Cover Art   

使用 main 元素

Bad:

...

查看更多关于HTML最佳实践_html/css_WEB-ITnose的详细内容...

  阅读:34次