[Bootstrap Basics] 04. The HTML and CSS coding specifications of Bootstrap, bootstrapcss

Source: Internet
Author: User

[Bootstrap Basics] 04. The HTML and CSS coding specifications of Bootstrap, bootstrapcss

HTML

  • Use two spaces to replace tabs-this is the only way to ensure consistent display in all environments.
  • The nested element should be indented once (that is, two spaces)
  • For attribute definitions, make sure that all double quotation marks are used. Do not use single quotation marks.
  • Do not add a slash to the end of the self-closing element-this is optional in the HTML5 specification.
  • Do not omit the optional ending tag (for example,</li>Or</body>).
  • <Html lang = "zh-CN"> we strongly recommend that you specify the lang attribute for the html root element to set the correct language for the document. This will help the speech synthesis tool determine the pronunciation it should adopt and help the translation tool determine the rules it should follow during translation.
  • <Meta charset = "UTF-8"> by explicitly declaring character encoding, the browser can quickly and easily determine the rendering method of page content.
  • <Meta http-equiv = "X-UA-Compatible" content = "IE = Edge"> IE supports<meta>Label to determine the IE version used to draw the current page. Unless there are strong special requirements, it is best to setEdge modeTo notify IE to adopt the latest supported mode.
  • According to HTML5 specifications, when introducing CSS and JavaScript files, you do not need to specifytypeAttribute, becausetext/cssAndtext/javascriptThey are their default values.
    <! -- Reference CSS --> <link rel = "stylesheet" href = "code-guide.css"> <! -- Inline style --> <style>/*... */</style> <! -- JavaScript --> <script src = "code-guide.js"> </script>
  • HTML attributes should be arranged in sequence as follows to ensure the code is easy to understand. Class is used to identify highly reusable components, so it should be placed first. Id is used to identify a specific component and should be used with caution (for example, bookmarks in the page ).
    • Class
    • Id, name
    • Data -*
    • Src, for, type, href
    • Title, alt
    • Aria-*, role

CSS

 

  • Use two spaces to replace tabs-this is the only way to ensure consistent display in all environments.
  • When grouping a selector, separate the selector into one row.
  • For ease of coding, add a space before the left curly braces of each declared block.
  • The right curly braces of the block should be arranged separately.
  • The:Insert a space.
  • For more accurate error reports, each statement should have an exclusive row.
  • All declaration statements should end with a semicolon. The semicolon following the last statement is optional. However, if you omit this semicolon, your code may be more error-prone.
  • For attribute values separated by commas, a space should be inserted after each comma (for example,box-shadow).
  • Do notrgb(),rgba(),hsl(),hsla()Orrect()ValueInternalInsert a space after a comma. This facilitates the division of multiple color values from multiple attribute values (both comma and space ).
  • For attribute values or color parameters, omit the value 0 before the decimal point smaller than 1 (for example,.5Replace0.5;-.5pxReplace-0.5px).
  • Hexadecimal values should all be in lower case, for example,#fff. When scanning documents, lowercase characters are easy to distinguish because their forms are easier to distinguish.
  • Try to use the hexadecimal value in short form, for example#fffReplace#ffffff.
  • Add double quotation marks to attributes in the selector. For example,input[type="text"]. It is optional only in some cases. However, double quotation marks are recommended for code consistency.
  • Avoid specifying the unit for the value 0. For example, usemargin: 0;Replacemargin: 0px;.
    /* Non-conforming CSS */. selector ,. selector-secondary ,. selector [type = text] {padding: 15px; margin: 0px 0px 15px; background-color: rgba (0, 0, 0, 0.5); box-shadow: 0px 1px 2px # CCC, inset 0 1px 0 # FFFFFF}/* compliant CSS */. selector ,. selector-secondary ,. selector [type = "text"] {padding: 15px; margin-bottom: 15px; background-color: rgba (0, 0 ,. 5); box-shadow: 0 1px 2px # ccc, inset 0 1px 0 # fff ;}
  • The relevant attribute Declaration should be a group and arranged in the following order:

    Positioning can remove elements from normal document streams and overwrite box model styles. The box model ranks second because it determines the size and position of the component.

    Other attributes only affect the internal (inside) of the component, or do not affect the first two sets of attributes.

To be honest and wise, the so-called norms are what everyone agrees to write code together.

I read the above on the Internet. I don't know whether to declare or not to repost. Some of them are reprinted, which is too troublesome. They are all basic things. Forget it.

 

Related Article

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.