in CSS , what is the difference between Cascading and inheritance? are both same thing?
+8
A:
Inheritance is about how properties trickle down from an element to it's children. Certain properties, like font-family
inherit. If you set a font-family on the body
, that font family will be inherited by all the elements within the body
. The same is true for color
, but it is not true for background
or height
which will always default to transparent
and auto
. In most cases this just makes sense. Why would the background inherit? that would be a pain. What if fonts didn't inherit? What would that even look like?
The cascade is about what take precedence when there is a conflict. The rules of the cascade include:
- Later properties override earlier properties
- More specific selectors override less specific selectors
- Specified properties override inherited properties
And so on. The cascade solves any conflict situations. It is the order in which properties are applied.
Eric Meyer
2010-03-09 05:53:13
+1 good answer @Eric
metal-gear-solid
2010-03-09 06:01:15