`
| 棄用屬性 | 效果 | CSS 替代 |
|---|---|---|
color / border-color | 線條顏色 | border-color / border-top-color |
size | 線條粗細 (高度) | height / border-width |
width | 線條寬度 | width / max-width + `margin-inline: auto` |
align | 水平對齊 | margin-inline: auto (置中) / `margin-left: 0` (左) / `margin-right: 0` (右) |
noshade | 無陰影 (純色線) | border: 0; border-top: 1px solid color; 或 `height: 1px; background: color;` |
/* 瀏覽器預設 hr 樣式差異大,建議先重置 */
hr {
border: 0; /* 移除預設邊框 */
border-top: 1px solid var(--color-border); /* 只保留上邊框作為分隔線 */
margin: 1.5rem auto; /* 上下間距、水平置中 */
width: 100%; /* 預設滿寬 */
clear: both; /* 清除浮動 (舊佈局相容) */
overflow: visible; /* 允許內容溢出 (如掛飾) */
}
/* 語意色彩 Token */
:root {
--color-border: oklch(0.85 0 0);
--color-divider: oklch(0.85 0 0);
--color-divider-strong: oklch(0.7 0 0);
--color-brand: oklch(0.55 0.15 250);
}
.divider-solid { border-top-style: solid; }
.divider-dashed { border-top-style: dashed; }
.divider-dotted { border-top-style: dotted; }
.divider-double { border-top: 3px double var(--color-divider); }
.divider-gradient {
border: 0;
height: 2px;
background: linear-gradient(90deg, transparent, var(--color-brand), transparent);
}
.divider-with-content {
display: flex;
align-items: center;
gap: 1rem;
border: 0;
color: var(--color-text-muted);
font-size: 0.875rem;
text-transform: uppercase;
letter-spacing: 0.1em;
}
.divider-with-content::before,
.divider-with-content::after {
content: "";
flex: 1;
height: 1px;
background: var(--color-divider);
}
.divider-with-content span { white-space: nowrap; }
使用:`
.divider-pattern {
border: 0;
height: 24px;
background: url("data:image/svg+xml,") center / 24px 24px repeat-x;
}
| 場景 | 推薦做法 | 理由 |
|---|---|---|
| 卡片間距 | Grid/Flex `gap` + 容器 `padding` | 語意清晰、無額外 DOM、響應式自然 |
| 區塊底部分隔 | `border-bottom` on section/article | 依附於內容區塊、無額外元素 |
| 表單欄位分組 | ` | 語意分組、無障礙友善 |
| 列表項分隔 | `li + li { border-top: 1px solid var(--divider); }` | 相鄰選擇器、首項無線 |
| 文字段落間裝飾線 | `::after` / `::before` 偽元素 | 不汙染 DOM、內容與裝飾分離 |
.article-section {
padding-block: 2rem;
}
.article-section + .article-section {
position: relative;
}
.article-section + .article-section::before {
content: "";
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 60px;
height: 3px;
background: linear-gradient(90deg, transparent, var(--color-brand), transparent);
border-radius: 2px;
}
/* 列表項細分隔 */
.comment-list li + li {
border-top: 1px solid var(--color-divider);
padding-top: 1.5rem;
margin-top: 1.5rem;
}
語意化 HTML 的核心精神:**標籤表達意思,CSS 表達外觀**。`