/* 未排序 */
.header {
z-index: 100;
color: #333;
position: relative;
padding: 1rem;
margin-bottom: 2rem;
border-bottom: 1px solid #eee;
font-size: 1.5rem;
}
/* 字母序排序 */
.header {
border-bottom: 1px solid #eee;
color: #333;
font-size: 1.5rem;
margin-bottom: 2rem;
padding: 1rem;
position: relative;
z-index: 100;
}
position 與 top/right/bottom/left 分離、font-size 與 line-height 分離| 指南 | 立場 | 替代方案 |
|---|---|---|
| Google HTML/CSS Style Guide | 字母序 | 工具強制 |
| Airbnb CSS / Sass Styleguide | 功能分組 | Concentric CSS / SMACSS 分類 |
| WordPress CSS Coding Standards | 功能分組 | 屬性分類排序 |
| ThinkUp CSS Style Guide | 字母序 | 自動化工具 |
| CSS Tricks / Modern CSS | 功能分組 | 邏輯分組 + 內部字母序 |
.card {
/* 1. 佈局/定位 - 決定元素在頁面位置 */
position: relative;
display: flex;
flex-direction: column;
z-index: 10;
/* 2. 盒模型 - 決定元素尺寸與間距 */
width: 100%;
max-width: 400px;
padding: 1.5rem;
margin: 0 auto;
border: 1px solid var(--color-border);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-md);
/* 3. 排版/文字 - 決定內容呈現 */
font-family: var(--font-sans);
font-size: var(--text-base);
line-height: 1.6;
color: var(--color-text);
text-align: left;
/* 4. 視覺/裝飾 - 非佈局視覺效果 */
background: var(--color-surface);
overflow: hidden;
/* 5. 動畫/過渡 */
transition: box-shadow 0.2s ease, transform 0.2s ease;
/* 6. 偽類/狀態 */
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card {
/* 佈局組內字母序 */
display: flex;
flex-direction: column;
position: relative;
z-index: 10;
/* 盒模型組內字母序 */
border: 1px solid var(--color-border);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-md);
margin: 0 auto;
max-width: 400px;
padding: 1.5rem;
width: 100%;
/* ... */ }
/* Stylelint 配置:功能分組 + 組內字母序 */
{
"plugins": ["stylelint-order"],
"rules": {
"order/order": [
"custom-properties",
"dollar-variables",
"at-rules",
"declarations"
],
"order/properties-order": [
/* 佈局 */
"position", "top", "right", "bottom", "left", "z-index",
"display", "flex-*", "grid-*", "float", "clear",
/* 盒模型 */
"width", "min-width", "max-width", "height", "min-height", "max-height",
"margin", "margin-*", "padding", "padding-*",
"border", "border-*", "border-radius", "box-shadow",
/* 排版 */
"font", "font-*", "line-height", "text-*", "letter-spacing", "word-spacing",
"color", "opacity",
/* 視覺 */
"background", "background-*", "overflow", "cursor",
/* 動畫 */
"transition", "transition-*", "animation", "animation-*",
"transform", "transform-*"
],
"order/alphabetical": false /* 組內不強制字母序 */
}
}
/* Prettier + Stylelint 保存即格式化,零心智負擔 */
/* Styled Components / Emotion 對象語法:天然分組、無順序爭議 */
const Card = styled.div`
/* 佈局 */
display: flex;
flex-direction: column;
position: relative;
z-index: 10;
/* 盒模型 */
width: 100%;
max-width: 400px;
padding: 1.5rem;
margin: 0 auto;
border: 1px solid ${tokens.border};
border-radius: ${tokens.radius.lg};
box-shadow: ${tokens.shadow.md};
/* 排版 */
font-family: ${tokens.font.sans};
font-size: ${tokens.text.base};
line-height: 1.6;
color: ${tokens.color.text};
/* 視覺 */
background: ${tokens.color.surface};
overflow: hidden;
/* 狀態 */
&:hover {
transform: translateY(-2px);
box-shadow: ${tokens.shadow.lg};
}
`;
字母序排序是工業化早期產物,現代 CSS 開發應擁抱語義化分組 + 自動化工具鏈,讓代碼表達設計意圖而非字母順序。