selector1, selector2, selectorN { declarations; }
,),全角逗號無效。/* 標題統一樣式 */
h1, h2, h3, h4, h5, h6 {
font-weight: 700;
line-height: 1.2;
color: #1a1a1a;
}
/* 表單元素統一基準 */
input, textarea, select, button {
font: inherit;
color: inherit;
box-sizing: border-box;
}
/* 重置列表樣式 */
ul, ol, menu { list-style: none; padding: 0; margin: 0; }
/* ID + 類 + 標籤 任意組合 */
#main-content, .article-body, article {
max-width: 42rem;
margin-inline: auto;
}
/* 偽類也可群組 */
button:focus,
a:focus,
input:focus,
select:focus {
outline: 2px solid #0066cc;
outline-offset: 2px;
}
/* design-tokens.css */
:root {
--color-primary: #0066cc;
--radius-md: 6px;
}
/* components.css -- 群組映射 Token */
.btn--primary,
.link--primary,
.badge--primary {
background-color: var(--color-primary);
}
.input,
.select,
.textarea {
border-radius: var(--radius-md);
}
修改 Token 即可全局同步,群組選擇器成為 **設計系統與組件的連接層**。
h1, .btn, #footer { color: red; } — 語義混亂,維護困難。.simple, .very .complex .nested .selector { },後者匹配成本高拖累前者。selector-list-comma-newline-after: "always"。群組選擇器是 **DRY (Don't Repeat Yourself) 原則在 CSS 的直接體現**。用對地方 (同語義、同層級、同複雜度),能大幅減少代碼體積、統一視覺語言、降低維護成本。配合 CSS 變數與設計系統,更是構建一致性體驗的關鍵紐帶。