We recommend that you use the CSS writing standard and sequence, and the css writing standard sequence.

Source: Internet
Author: User
Tags print print

We recommend that you use the CSS writing standard and sequence, and the css writing standard sequence.

After writing CSS for so long, most front-end er did not write CSS code according to good CSS writing specifications, which will affect the reading experience of the Code, here we will summarize a CSS writing standard and a CSS writing sequence for your reference. These are some foreign articles and my personal experience, I think it is worth learning for front-end users who write CSS.

CSS writing Sequence

1. position attributes (position, top, right, z-index, display, float, etc)

2. Size (width, height, padding, margin)

3. text series (font, line-height, letter-spacing, color-text-align, etc)

4. background (background, border, etc)

5. Others (animation, transition, etc)

CSS writing standards use CSS abbreviations

Some CSS attributes can be abbreviated, such as padding, margin, and font. This simplifies the code and improves the user's reading experience.

Remove "0" before the decimal point"

Abbreviated name

Many users prefer to use the abbreviated class name, but only when you understand your name can it be abbreviated!

Hexadecimal color code abbreviation

Some color codes can be abbreviated. We recommend that you use them to improve user experience.

CSS selector naming rules

1. Long names or phrases can be named by a hyphen.

2. It is not recommended to use the underscore "_" to name the CSS selector. Why?

  • Press one shift key when you enter it;
  • Browser compatibility problems (for example, the _ tips selector name is invalid in IE6)
  • The JavaScript variable name can be well distinguished (the JS variable name is "_")

Do not use id at will

Id is unique in JS and cannot be used multiple times, but the class selector can be used repeatedly. In addition, the priority of id is higher than that of class, so id should be used as needed, it cannot be abused.

Add a status prefix to a selector

Sometimes you can add a status prefix to the selector to make the semantics clearer. For example, you can add a ". is-" prefix.

CSS naming rules

Header: header
Content: content/container
End: footer
Navigation: nav
Sidebar: sidebar
Column: column
Page peripheral control overall Board Width: wrapper
Left right center
Logon entry: loginbar
Logo: logo
Advertisement: banner
Page subject: main
Hotspot: hot
News: news
Download: download
Subnavigation: subnav
Menu: menu
Sub menu: submenu
Search: search
Link: friendlink
Footer: footer
Copyright: copyright
Scroll: scroll
Content: content
Tags: tags
Article list: list
Message: msg
Tips: tips
Topic title: title
Join: joinus
Guide: guide
Service: service
Registration: regsiter
Status: status
Vote: vote
Partner: partner

Annotation Syntax:

/* Header */
Content Area
/* End Header */

Id:

1) Page Structure

Container: container
Header: header
Content: content/container
Page subject: main
Footer: footer
Navigation: nav
Sidebar: sidebar
Column: column
Page peripheral control overall Board Width: wrapper
Left right center

(2) Navigation

Navigation: nav
Main navigation: mainnav
Subnavigation: subnav
Top navigation: topnav
Side navigation: sidebar
Left Navigation: leftsidebar
Right navigation: rightsidebar
Menu: menu
Sub menu: submenu
Title: title
Abstract: summary

(3) Functions

Logo: logo
Advertisement: banner
Login: login
Logon entry: loginbar
Registration: register
Search: search
Functional Area: shop
Title: title
Join: joinus
Status: status
Button: btn
Scroll: scroll
Tab
Article list: list
Message: msg
Current: current
Tips: tips
Icon: icon
Note: note
Guide: guild
Service: service
Hotspot: hot
News: news
Download: download
Vote: vote
Partner: partner
Link
Copyright: copyright

Note ::

1. All are in lower case;
2. Try to use English;
3. Do not add a hyphen (-) or underscore;
4. Try not to be abbreviated, except words that can be understood without looking at them.

CSS style sheet file name

Main master.css
Module module.css
Basic shared base.css
Layout.css
Themes.css
Columns.css
Text font.css
Form forms.css
Patch mend.css
Print print.css

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.