h1 { font-size: 2em; margin: 0.67em 0; }加上 !important 後,優先權順序反轉:
使用者 !important > 作者 !important > 使用者一般 > 作者一般 > 瀏覽器預設
/* 瀏覽器預設 */
h1 { color: black; }
/* 作者樣式 */
h1 { color: blue; } /* 勝出:作者 > 瀏覽器 */
/* 使用者樣式 (瀏覽器設定) */
h1 { color: green !important; } /* 勝出:使用者 !important 最高 */
/* 作者加 !important 試圖覆蓋 */
h1 { color: red !important; } /* 敗給:使用者 !important > 作者 !important */
!important,尊重使用者自主權上述三層是「來源」層級。在同一来源(如作者樣式)內,再依 Specificity 計算:
/* 同屬作者樣式,比較 Specificity */
#header .nav a { color: red; } /* 0,1,1,1 */
.nav-link { color: blue; } /* 0,0,1,0 → 敗給上一行 */
a { color: green; } /* 0,0,0,1 → 最低 */