Five guidelines to help you write maintainable CSS code

Five guidelines to help you write maintainable CSS code
1. Add a comment block at the beginning of the style sheet to describe the creation date, creator, tags and other notes of the style sheet.

Copy code
The code is as follows:

Example Source Code:
/*
---------------------------------
Site: Site name
Author: 52CSS.com
Updated: Date and time
Updated by: Name
---------------------------------
*/

2. Including public color marking

Copy code
The code is as follows:

Example Source Code:
/*
---------------------------------
COLORS
Body background: #def455
Container background: #fff
Main Text: #333
Links: #00600f
Visited links: #098761
Hover links: #aaf433
H1, H2, H3: #960
H4, H5, H6: #000
---------------------------------
*/

3. Give ID and Class meaningful names <br />Not recommended naming method:
Example Source Code:

Copy code
The code is as follows:

.green-box { ... }
#big-text { ... }

Recommended naming convention:
Example Source Code:

Copy code
The code is as follows:

.pullquote { ... }
#introduction {... }

4. Integrate related style rules
Example Source Code:

Copy code
The code is as follows:

#header { ... }
#header h1 { ... }
#header h1 img { ... }
#header form { ... }
#header a#skip { ... }
#navigation { ... }
#navigation ul { ... }
#navigation ul li { ... }
#navigation ul li a { ... }
#navigation ul li a:hover { ... }
#content { ... }
#content h2 { ... }
#content p { ... }
#content ul { ... }
#content ul li { ... }

5. Add clear comments to styles
Example Source Code:

Copy code
The code is as follows:

/*
---------------------------------
Header styles
---------------------------------
*/
#header { ... }
#header h1 { ... }
#header h1 img { ... }
#header form { ... }
/*
---------------------------------
navigation styles
---------------------------------
*/
#navigation { ... }

<<:  JS ES new feature of variable decoupling assignment

>>:  HTML form value transfer example through get method

Recommend

Detailed tutorial on installing the jenkins container in a docker environment

Recommended Docker learning materials: https://ww...

MySQL database development specifications [recommended]

Recently, we have been capturing SQL online for o...

Suggestions on creating business HTML emails

Through permission-based email marketing, not onl...

MySQL aggregate function sorting

Table of contents MySQL result sorting - Aggregat...

Implementation of Docker deployment of ElasticSearch and ElasticSearch-Head

This article mainly explains how to deploy Elasti...

CenterOS7 installation and configuration environment jdk1.8 tutorial

1. Uninstall the JDK that comes with centeros fir...

Steps to introduce PWA into Vue project

Table of contents 1. Install dependencies 2. Conf...

Docker container time zone error issue

Table of contents background question Problem ana...

Instructions for recovering data after accidental deletion of MySQL database

In daily operation and maintenance work, backup o...

mysql8.0.23 linux (centos7) installation complete and detailed tutorial

Table of contents What is a relational database? ...

How to get the width and height of the image in WeChat applet

origin Recently, I am working on requirement A, i...