Therefore, the structure is excellent Code It can greatly optimize its maintainability. The following lists four methods to improve the maintainability of CSS files. This serves as a guide for Web Front-end development with a good CSS style Organization habit.
I. CSS style file Decomposition
For small projects, the code is divided into several parts by PAGE structure or page content before writing code, and comments are given. For example, you can separate global styles, la S, font styles, forms, comments, and others into several different parts to continue working.
For large projects, this obviously won't have any effect. In this case, you need to break down the style into several different style table files. The following example of the master stylesheet method is used to import other style files. Using this method can not only optimize the style structure, but also reduce unnecessary server requests. There are many methods to break down files. Master stylesheet uses the most common one.
@ Import "reset.css ";
@ Import "layout.css ";
@ Import "colors.css ";
@ Import "typography.css ";
@ Import "flash.css ";
/* @ Import "debugging.css ";*/
In addition, you can add the CSS file upgrade mark or some diagnosis and Other Measures for large projects. Everyone should pay attention to summing up and thinking in the implementation work. You are also welcome to refer to jb51.net for more information.Article.
2. Create an index for the CSS file
To quickly understand the structure of the entire CSS file, creating a file index at the beginning of the file is a good choice.
A feasible method is to create a tree index. The structure ID and class can both be a branch of the tree.
[Layout]
* Body
+ Header/# Header
+ Content/# Content
-Left column/# leftcolumn
-Right column/# rightcolumn
-Sidebar/# sidebar
-RSS/# RSS
-Search/# search
-Boxes/. Box
-Sideblog/# sideblog
+ Footer/# footer
Navigation # navbar
Advertisements. Ads
Content Header H2
Alternatively, you can:
[Contents]
1. Body
2. Header/# Header
2.1. navigation/# navbar
3. Content/# Content
3.1. left column/# leftcolumn
3.2. right column/# rightcolumn
3.3. Sidebar/# sidebar
3.3.1. RSS/# RSS
3.3.2. Search/# search
3.3.3. Boxes/. Box
3.3.4. sideblog/# sideblog
3.3.5. Advertisements/. Ads
4. footer/# footer
The other method is simply to list the content without indentation. In the following example, if you want to jump to the RSS part, you only need to perform a simple search.
[Contents]
1. Body
2. Header/# Header
3. navigation/# navbar
4. Content/# Content
5. left column/# leftcolumn
6. right column/# rightcolumn
7. Sidebar/# sidebar
8. RSS/# RSS
9. Search/# search
10. Boxes/. Box
11. sideblog/# sideblog
12. Advertisements/. Ads
13. footer/# footer
/* -- [8. RSS/# RSS] -- */
# RSS {...}
# Rss img {...}
Defining such a style search can effectively make it easy for others to read and learn your code. When creating a large project, you can print the search to facilitate reading the code.