外部 CSS 中 h1, body 樣式不生效,寫在 HTML <style> 或 style="" 卻生效。.one, .two 類選擇器正常。
| 來源 | 優先級權重 | 示例 |
|---|---|---|
| 內聯 style | 1000 | <h1 style="color:red"> |
| ID 選擇器 | 100 | #header |
| 類/屬性/偽類 | 10 | .one, [type=text], :hover |
| 元素/偽元素 | 1 | h1, body, ::before |
| 通配符/繼承 | 0 | *, body { color: inherit } |
<style> 在 <link> 之後,同權重後者勝出body { color: black !important } 或 #container h1 等高權重規則Ctrl+F5 或加版本號 style.css?v=2h1 打勾/劃掉的規則來源!important 強制覆蓋<link rel="stylesheet"> 在 <style> 之前!important 測試:h1 { color: red !important } 若生效說明是優先級問題!important,改用更具體選擇器(如 .page-header h1)