CSS 無邏輯分支,可讀性完全依賴結構組織。統一格式化規範是專業團隊基礎設施。
/* ✅ 推薦:多行展開,屬性分組,尾隨分號 */
.component {
/* Layout */
display: flex;
flex-direction: column;
gap: 1rem;
/* Box Model */
padding: 1.5rem;
border: 1px solid var(--color-border);
border-radius: 8px;
/* Visual */
background: var(--color-surface);
box-shadow: var(--shadow-md);
/* Typography */
font-size: 0.9375rem;
line-height: 1.6;
color: var(--color-text);
}
/* ❌ 避免:單行擠壓、無分組、無分號 */
.component{display:flex;flex-direction:column;padding:1.5rem;border:1px solid #eee;border-radius:8px;background:#fff}
/* 區塊分隔註解:等號錨點支援編輯器大綱跳轉 */
@import "reset.css";
@import "variables.css";
/* =RESET ============================ */
/* =VARIABLES ======================== */
/* =LAYOUT =========================== */
.layout { display: grid; }
.header { grid-area: header; }
.main { grid-area: main; }
.sidebar { grid-area: sidebar; }
.footer { grid-area: footer; }
/* =COMPONENTS ======================= */
/* == Button ========================= */
.btn { ... }
.btn--primary { ... }
/* == Card =========================== */
.card { ... }
.card__header { ... }
.card__body { ... }
.card__footer { ... }
/* =UTILITIES ======================== */
.visually-hidden { ... }
/*!
* Design System v3.2.0
* Architecture: ITCSS (Settings → Tools → Generic → Elements → Objects → Components → Utilities)
* Tokens: colors, spacing, typography, breakpoints, shadows, z-index, transitions
* Methodology: BEM + Utility-first hybrid
* Browser Support: >0.5%, last 2 versions, not dead, not IE 11
* Build: Vite + PostCSS (Autoprefixer, cssnano, PostCSS Nesting)
* Lint: Stylelint (BEM pattern, logical properties, no ID selectors)
* Docs: Storybook + Style Dictionary
*/
/* package.json scripts */
"scripts": {
"lint:css": "stylelint \"**/*.css\" --fix",
"format:css": "prettier --write \"**/*.css\"",
"check:css": "stylelint \"**/*.css\" && prettier --check \"**/*.css\""
}
/* .github/workflows/ci.yml */
- name: CSS Lint & Format
run: npm run check:css
/* Husky pre-commit 鉤子 */
npx husky add .husky/pre-commit "npx lint-staged"
/* lint-staged.config.js */
module.exports = {
'*.{css,scss,less}': ['stylelint --fix', 'prettier --write']
};
!important (或有明確註解理由)@see 註解連結設計稿/文檔