<font> 到現代 CSS 排版系統<font> 標籤 (勿用)<font size="2" face="Arial" color="#ff0000">文字</font>
缺點:結構與表現耦合、維護困難、無回應式能力、違反 HTML5 規範。
| 屬性 | 說明 | 範例 |
|---|---|---|
| font-family | 字體堆疊,備援機制 | font-family: "PingFang TC", "Microsoft JhengHei", sans-serif; |
| font-size | 字體大小,相對單位優先 | font-size: 1rem; /* 16px */ |
| font-weight | 粗細 | font-weight: 400 | 700 | bold; |
| font-style | 斜體 | font-style: italic | normal; |
| line-height | 行高 (無單位為倍數) | line-height: 1.6; |
| color | 文字顏色 | color: #212529; |
| font | 速記屬性 | font: 1rem/1.6 "PingFang TC", sans-serif; |
/* @font-face 自訂字體 */
@font-face {
font-family: 'MyFont';
src: url('/fonts/myfont.woff2') format('woff2'),
url('/fonts/myfont.woff') format('woff');
font-display: swap; /* 關鍵:避免字體載入期間文字隱形 */
}
/* Google Fonts 预连接 + 预加载 */
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;700&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;700&display=swap" media="print" onload="this.media='all'">
:root { font-size: 16px; } /* 基準 */
@media (min-width: 768px) { :root { font-size: 18px; } }
@media (min-width: 1200px) { :root { font-size: 20px; } }
/* 全站使用 rem,自動隨根元素縮放 */
單一字體檔包含多種字重、寬度、斜度軸 (wght, wdth, slnt, opsz...),大幅減少請求數與檔案體積。支援瀏覽器:Chrome 62+, Firefox 62+, Safari 11+, Edge 79+。