`
` 標籤雖在 HTML5 中多屬性已廢棄 (轉移至 CSS),但理解其歷史屬性有助於維護舊專案與掌握樣式演進邏輯。| 屬性 | 作用 | 現代替代 (CSS) |
|---|---|---|
| `bgcolor` | 頁面背景顏色 | `body { background-color: #fff; }` |
| `background` | 背景圖片 URL | `body { background-image: url(...); }` |
| `text` | 默認文本顏色 | `body { color: #333; }` |
| 屬性 | 狀態 | 現代替代 (CSS 偽類) |
|---|---|---|
| `link` | 未訪問鏈接 | `a:link { color: #0066cc; }` |
| `vlink` | 已訪問鏈接 | `a:visited { color: #663399; }` |
| `alink` | 點擊瞬間 (激活態) | `a:active { color: #ff0000; }` |
| — | 懸停態 (HTML 無屬性) | `a:hover { color: #ff6600; }` |
現代寫法統一用 CSS,並遵循 **LVHA 順序**:`:link` → `:visited` → `:hover` → `:active`,避免優先級覆蓋問題。
| 屬性 | 作用 | 現代替代 (CSS) |
|---|---|---|
| `topmargin` | 上邊距 (像素) | `body { margin-top: 0; }` 或 `padding-top` |
| `leftmargin` | 左邊距 | `body { margin-left: 0; }` |
| `rightmargin` | 右邊距 | `body { margin-right: 0; }` |
| `bottommargin` | 下邊距 | `body { margin-bottom: 0; }` |
| `marginwidth` / `marginheight` | IE 專有水平/垂直邊距 | 同上 |
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="utf-8">
<title>文檔標題</title>
<style>
/* CSS Reset 片段 */
html, body { margin: 0; padding: 0; }
body {
background-color: #f5f5f5;
color: #333;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
line-height: 1.6;
}
a:link { color: #0066cc; text-decoration: none; }
a:visited { color: #663399; }
a:hover { color: #ff6600; text-decoration: underline; }
a:active { color: #ff0000; }
</style>
</head>
<body>
<!-- 內容 -->
</body>
</html>
`bgcolor, background, text, link, vlink, alink, topmargin, leftmargin, rightmargin, bottommargin, marginwidth, marginheight` — 全部遷移至 CSS。
掌握歷史屬性是為了讀懂舊代碼;新專案請 100% 使用 CSS 控制表現,結構與樣式分離。