一、在樣式表開頭添加一個註解區塊,用以描述這個樣式表的建立日期、建立者、標記等備忘資訊。
Example Source Code: /* --------------------------------- Site: Site name Author: 52CSS.com Updated: Date and time Updated by: Name --------------------------------- */ |
二、包括公用顏色標記
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 --------------------------------- */ |
三、給ID和Class進行有意義的命名
不推薦的命名方式:
Example Source Code: .green-box { ... } #big-text { ... } |
推薦使用的命名方式:
Example Source Code: .pullquote {... } #introduction {... } |
四、將關聯的樣式規則進行整合
Example Source Code: #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 { ... } |
五、給樣式添加清晰的注釋
Example Source Code: /* --------------------------------- header styles --------------------------------- */ #header { ... } #header h1 { ... } #header h1 img { ... } #header form { ... } /* --------------------------------- navigation styles --------------------------------- */ #navigation { ... } |