萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網路程式設計 >> Android 開發

HTML <body> 標籤核心屬性與現代 CSS 替代方案

已棄用的表現屬性 (HTML5 不建議使用)

屬性用途CSS 替代
bgcolor背景顏色background-color
background背景圖片background-image
text文字顏色color
link未造訪連結顏色a:link { color }
vlink已造訪連結顏色a:visited { color }
alink點擊瞬間連結顏色a:active { color }
topmargin上邊距margin-top / body { margin:0 }
leftmargin左邊距margin-left
rightmargin右邊距margin-right
bottommargin下邊距margin-bottom

現代最佳實踐

/* CSS Reset / Normalize 片段 */
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  color: #212529;
  background-color: #fff;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: #0d6efd; text-decoration: underline; }
a:hover { color: #0a58ca; }

保留的實用屬性

  • onload, onunload 等事件屬性(建議改用 `addEventListener`)
  • class, id, style, data-* 通用屬性

總結

所有表現屬性已移至 CSS,HTML 僅保留結構與語意。採用 CSS Reset/Normalize 確保跨瀏覽器一致基線,再依設計系統客製化 body 樣式。

copyright © 萬盛學電腦網 all rights reserved