Code Guide (CSS)

Source: Internet
Author: User

Golden rule

Every line of code should appear to is written by a single person, no matter the number of contributors.

1.Syntax

  • Use soft tabs with both Spaces-they ' re the only-to-guarantee code renders the same in any environment.
  • When grouping selectors, keep individual selectors to a.
  • Include one space before the opening brace of declaration blocks for legibility.
  • Place closing braces of declaration blocks in a new line.
  • Include one space after:for each declaration.
  • Each of the declaration should appear on its own line for more accurate error reporting.
  • End all declarrations with a semi-colon. The last declaration was optional, but your code was more error prone without it.
  • Comma-separated property values should include a space after each Comma (e.g., Box-shadow).
  • Don ' t includes spaces after commas within RGB (), Rgba (), HSL (), Hsla (), rect ().
  • Don ' t prefix property values or color parameters with a leading zero. e.g. 5px;
  • #fff. Not #FFF. Not #ffffff.
  • Quote attribute values in selectors.e.g., inpput[type= "text"].
  • Avoid 0px, just 0. e.g., margin:0;

2.Declaration Order

    • Related property declarations should is grouped together following the order:
      1. Positioning
      2. Box model
      3. Typographic
      4. Visual
    • Po

3.Language attribute

4.Character encoding

    • <meta charset= "UTF-8" >

5.CSS and JavaScript includes

    • Typically there is no need to specify a type when including CSS and JavaScript files as text/css and Text/javascript are T Here rerspictive defaults
    • <link rel= "stylesheets href=" Code-guide.css ">
    • <script src=code-guide.js "></script>

6.Practicality over Purity

    • Strive to maintain HTML standards and semantics, but not at the expense of practicality. Use the least amount of markup with the fewest intricacies whenever possible.

7.Attribute Order

    • HTML attributes should come in this particular order for easier reading of code.
      • Class
      • ID, name
      • data-*
      • SRC, for, type, href, value
      • Title, Alt
      • Role, aria-*
    • Classes make to great reusable components, so they come first. Ids is more specific and should is used sparingly, so they come second.

8.Boolean attributes

    • A Boolean attributes is one that needs no declared value
    • e.g.: <input type= "Text" disabled>

9.Reducing markup

    • Whenever possible, avoid superfluous parent elements when writing HTML.

10.JavaScript generated markup

    • Writing markup in JavaScript file makes the content harder to find, harder to edit, and less performant. Avoid it whenever possible.

Code Guide (CSS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.