Article Introduction: Most of the front-end ER did not follow a good CSS writing code to write CSS, this will affect the reading experience of the code, here I summarize a CSS writing specifications, CSS writing order for everyone's reference, these are referred to some foreign articles and my personal experience summed up, I think it is worth learning for the front-end users who write CSS. |
Wrote a long time CSS, but most of the front end ER did not follow the good CSS writing code to write CSS, this will affect the code reading experience, here I summarize a CSS writing order for everyone to reference, these are referred to some foreign articles and my personal experience summed up, I think it is worth learning for the front-end users who write CSS.
CSS Writing Order
Position properties (position, top, right, z-index, display, float, etc.)
Size (width, height, padding, margin)
Text series (font, Line-height, letter-spacing, color-text-align, etc.)
Background (background, border, etc.)
Other (animation, transition, etc.)
CSS Writing specification
Use CSS abbreviation properties
CSS Some attributes can be abbreviated, such as Padding,margin,font and so on, so that the streamlining of code at the same time improve the user's reading experience.
Remove the "0″" before the decimal point
Abbreviated name
Many users like shorthand class name, but the premise is to let people understand your name can be abbreviated Oh!
16 Binary color code abbreviation
Some color code can be abbreviated, we will try to abbreviate it, improve the user experience primarily.
Hyphen CSS Selector naming specification
1. Long names or phrases can be named for selectors using the middle horizontal line.
2. It is not recommended to use the "_" Underline to name the CSS selector, why?
Press one SHIFT key less when typing;
Browser compatibility issues (such as naming using _tips selectors, which are not valid in IE6)
Good at distinguishing javascript variable naming (JS variable name is with "_")
Here is a detailed discussion of dashes and underscores, English: Click to view the Chinese text: Click to view
Do not use the ID arbitrarily
ID in JS is unique, can not be used many times, and the use of class classes selector can be reused, the other ID priority and class, so the ID should be used on demand, and can not be abused.
Add a status prefix to the selector
Sometimes you can add a prefix for the state to the selector to make the semantics clearer, such as the ". is-" prefix that is added to the following image.