統一命名慣例(BEM/功能性/語義化)、屬性聲明順序(佈局→盒模型→文字→裝飾→動畫)、註釋風格。
/*
Project: MySite
Author: Jane Dev
Date: 2024-01-15
Color Palette: #0066cc (primary), #f4f4f4 (bg), #333 (text)
*/
方便團隊協作與後續維護。
/* 差 */ .col-left, .red-btn, .big-font
/* 好 */ .sidebar, .btn-primary, .heading-lg
重構時不需改 HTML,只改 CSS。
.nav-item 而非 .nav_item。避免舊瀏覽器解析問題,且與 JS 變數命名(camelCase/underscore)區分。
/* 冗長 */
h1, h2 { font-size: 2em; color: #333; border-bottom: 1px solid #ccc; }
/* 精簡 */
h1, h2 { font: bold 2em/1.2 "Microsoft YaHei"; color: #333; border-bottom: 1px solid #ccc; }
零值省略單位:margin: 0; 而非 margin: 0px;。
現代引擎標準一致性高,優先修正標準合規問題,再處理特定引擎 Bug。
base.css、layout.css、components/、utils.css、theme.css@import 或建置工具(PostCSS/Vite/Webpack)統一入口。