tags:

views:

82

answers:

2

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:

  1. Later properties override earlier properties
  2. More specific selectors override less specific selectors
  3. 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
+1 good answer @Eric
metal-gear-solid