1. Arrange css in alphabetical order
Unalphabetically arranged:
Div # header h1 {
Z-index: 101;
Color: #000 ;:
Position: relative;
Line-height: 24px;
Margin-right: 48px;
Border-bottom: 1px solid # dedede;
Font-size: 18px;
}
In alphabetical order:
Div # header h1 {
Border-bottom: 1px solid # dedede;
Color: #000;
Font-size: 18px;
Line-height: 24px;
Margin-right: 48px;
Position: relative;
Z-index: 101;
}
The reason is: you can better find a property.
2. Better css Structure
Css comments are used to group css. This structure is clear and facilitates collaborative design.
/***** Reset *****/
Xxxxxxx {www.sytm.net}
Xxxxx {xxxxx}
/***** Layouts *****/
Xxxxxxx {www.sytm.net}
Xxxxx {xxxxx}
3. Maintain consistency
It is better to write all the attributes of a selector in one row or one row for each attribute. If you like to write a line, because writing a line in each line will make the entire document feel too long and it is inconvenient to find it. However
Another person sent to the team, but he liked to arrange a row in each sentence. What should I do? In fact, it is very simple to take the css for w3c verification. It will have a result that will be automatically converted to each row.
4. Mark first and then css
It is not easy to write css after marking html. For example, to write a page, first write a basic tag structure <body>
<Div id = "wrapper">
<Div id = "header"> <! -- End # header -->
<Div id = "container">
<Div id = "content">
</Div> <! -- End # content -->
<Div id = "sidebar">
</Div> <! -- End # sidebarr -->
</Div> <! -- End # container -->
<Div id = "footer">
</Div>! <-- End # footer -->
</Div> <! -- End # wrapper -->
</Body>
Then, we try to make good use of the sub-selector, instead of adding a selector to the sub-Selector as soon as possible.
5. CSS Reset/Reset
You can copy Eric Meyer Reset, YUI Reset, or other css reset, but you should change it to your own reset based on your project.
* {Margin: 0; padding: 0;} does not apply to some elements, such as single-choice buttons. However, if there are single-choice buttons, just reset them.