不要滥用div,保持代码的整洁-----Coding Clean and Semantic Templates

 

本文旨在介绍如何保证页面代码的整洁、以维护性。使用有语义的页面标签,减少

标签的滥用。

1. 移除不必要的

标签

    嵌套在

    外面的标签没有必要

    2. 使用有语义的标记

       

      等标签,替代

      ,即便样式表丢失,仍然保证页面的可读性。

      3. 尽量少的使用

      标签

      4. 代码缩进格式

      5. 在

      结尾处加上这个
      块的注释

       

       

       

       

      原文地址:http://www.webdesignerwall.com/tutorials/coding-clean-and-semantic-templates/

       

      If you are the guy who uses

      tag for everything, this post is for you. It focuses on how you can write clean HTML code by using semantic markups and minimize the use of
      tag. Have you ever edited someone’s templates, don’t those messy tags drive you crazy? Not only writing clean templates can benefit yourself, but your team as well. It will save you time when you have to debug and edit (particularly the large projects).

       

      1. Remove The Unnecessary
      Tags

      I’ve seen a lot of people wrap a

      tag around the or
        menu list. Why create an extra
        tag that you don’t need? You can achieve the same result by applying the CSS rules to the selector.

        Example 1:

        The example below shows how you can drop the

        tag and declare the styling to the form selector.

        不要滥用div,保持代码的整洁-----Coding Clean and Semantic Templates_第1张图片

        Example 2:

        Sometimes we wrap the content with an extra

        tag strictly for spacing purposes. The example on the left uses a , I know it is the closing tag for
        .

        Example:

        I usually insert a HTML comment tag right after the closing

        tag. I use the forward slash to indicate it is the closing tag.

        不要滥用div,保持代码的整洁-----Coding Clean and Semantic Templates_第7张图片

        Conclusion

        • Minimize the use of
          tags.
        • You should only use the
          tag for the main layout sections such as: header, content, sidebar, and footer.
        • The content should be in semantic HTML tags, not
          tags.
        • Format the source code and label the closing
        tags.

你可能感兴趣的:(web设计,用户体验,semantic,templates,div,debugging,tags,css)