1. Avoid excessive restraint:
//Not recommended Ul.nav {..} //recommended. NAV {..}
2. Avoid too long descendant selectors:
{..}
3. Avoid chain (intersection) Selectors:
{..} {..}
4. Use the compound (compact) syntax:
//Not recommended. SomeClass{Padding-top:20px;Padding-bottom:20px;Padding-left:10px;Padding-right:10px;background:#000;Background-image:URL (.. /imgs/carrot.png);background-position:Bottom;background-repeat:Repeat-x;}//recommended. SomeClass{padding:20px 10px 20px 10px;background:#000 url (.. /imgs/carrot.png) Repeat-x Bottom;}
5. Avoid unnecessary namespaces
{..} {..}
6. Avoid unnecessary duplication
//not recommended. SomeClass { color : red ; background : blue ; font-size : 15px ;} Otherclass { color : red ; background : blue ; font-size : 15px ;} //recommended. SomeClass,. Otherclass { color : red ; background : blue ; font-size : 15px ;}
7. Avoid using hack: use conditional annotations instead of hack
8. Remove redundant structures (frameworks) and reset (resets):
(1) Reset and Eric Meyer ' s reset (reset) using the CSS framework, Reset,yui Grid CSS
(2) Resets can remove default styles from different browsers, making the page consistent across browsers
9, the CSS into a clear structure block :
(1) Separating and composing the declaration of CSS file with comments
(2) Split layout style, which is to give each layout a separate CSS file
10, use white : Nested code with a tab indentation, all properties on a separate line
11. Develop a set of CSS standards: be sure to develop the habit of writing comments for CSS
12, compression code :
Compression is a good solution, but only when published, YUI compressor and csstidy are experts in this area, they can remove redundant code, check the properties of each other to cover the error.
Many popular editors, such as BBEdit, TextMate, and TopStyle, can help you format your CSS code as you want, and you can also use PHP to process your CSS using server compression, and you'll find more CSS optimizations and compressed CSS tools.
13, it is best to use the name of the expression semantics: a good CSS class name should describe what it is and not what it looks like.
14, avoid!importants: In fact, you should also be able to use other high-quality selectors.
15. Simplify the rules as much as possible: You can further merge the repeating rules in different classes.
16. Merging CSS Files
Optimization rules for CSS