Five ways to improve the maintainability of a CSS file

Source: Internet
Author: User
Tags header

After completing a front-end job, many people forget the structure and details of the project. However, the code is not immediately complete stereotypes, the rest of the time there is continuous maintenance work, and these jobs may not be done by yourself. Therefore, the good structure of the code to a large extent to optimize its maintainability. Here are five ways to improve the maintainability of a CSS file, which is a good CSS style guide.

1. Break down your style

For small projects, before writing code, divide the code into pieces and annotate it by page structure or page content. For example, you can continue working by dividing global styles, layouts, font styles, forms, comments, and other pieces into several different blocks, respectively.

For larger projects, this obviously won't have any effect. At this point, you need to decompose the styles into several different style sheet files. The following Master stylesheet is an example of this approach, and its work is mainly to import other style files. Using this method not only optimizes the style structure, but also helps reduce some unnecessary server requests. There are many ways to decompose files, and master stylesheet uses the most common one.

/*------------------------------------------------------------------

[Master Stylesheet]
Project: Smashing Magazine
Version: 1.1
Last change: 05/02/08 [fixed Float bug, vf]
Assigned to: Vitaly Friedman (vf), Sven Lennartz (sl)
Primary use: Magazine
-------------------------------------------------------------------*/
@import "reset.css";
@import "layout.css";
@import "colors.css";
@import "typography.css";
@import "flash.css";
/* @import "debugging.css"; */

For large projects, you can also add a CSS file upgrade logo or some diagnostic measures, no longer detailed here.

2. Set up CSS file index

In order to quickly understand the structure of the entire CSS file, it is a good choice to establish a file index at the beginning of the file. One possible way to do this is to create a tree index: Both the ID and class on the structure can be a branch of the tree. As follows:

/*------------------------------------------------------------------
[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
——————————————————————-*/

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.