CSS 部分屬性 (color, font-*, line-height, text-*) 會自動繼承給子孫元素。若需讓特定子元素「脫離」繼承,需顯式覆寫。
font-family, font-size, font-weight, font-style, line-height, colortext-align, text-indent, text-transform, letter-spacing, word-spacinglist-stylecursorvisibility/* 父層設定 */
body {
font-family: Verdana, sans-serif;
}
/* 子元素 p 想用 Times */
p {
font-family: Times, "Times New Roman", serif; /* 直接覆寫,切斷繼承鏈 */
}
| 關鍵字 | 效果 |
|---|---|
inherit | 強制繼承父元素計算值 (含非繼承屬性如 border) |
initial | 重置為瀏覽器預設值 (CSS 初始值) |
unset | 繼承屬性→inherit,非繼承屬性→initial |
revert | 重置為瀏覽器/用戶代理樣式表值 (CSS4) |