Why does a CSS property inherit on one element but not another?
Quick answer
CSS inheritance depends on the property: color normally inherits a parent’s computed value, while border normally does not. A value specified on the child means it does not simply receive the parent’s value for that property. Check whether the property inherits by default, then compare the parent’s and child’s computed values and review the child’s applicable rules. [S1]
The question, the details, the next step.
A practical checklist
Select the child and confirm its parent in the element tree.
Check whether the specific property inherits by default.
Compare the parent’s and child’s computed values.
Review the rules that apply to the child.
Specify a child value when it should differ from the inherited value.
A few more useful answers
Does every CSS property inherit from its parent?
No. Inheritance is property-specific. For example, color inherits by default, while border does not; check the property’s definition when unsure. [S1]
What should I compare when a child’s value seems wrong?
Compare the computed values on the parent and child, then review the rules that apply to the child. That helps distinguish default inheritance behavior from a value specified on the child. [S1]
Why check the property’s definition?
A property’s definition tells you whether it inherits by default. The parent’s value is not automatically transferred for a property that does not inherit. [S1]
Sources
References used for this guide.
- [S1] Inheritance — MDN developer.mozilla.org · Checked
