Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Joshua Thompson
Joshua Thompson
1,229 Points

What is the difference between inheritance and descendant in CSS?

Basically what the title is asking :P I am just getting a bit confused between them.

2 Answers

Neville Barrett
Neville Barrett
6,141 Points

Hey Joshua,

Inheritance is a way of propagating property values from parent elements to their children. Some CSS properties are inherited by the children of elements by default. For example, if you set the body tag of a page to a specific font, that font will be inherited by other elements, such as headings and paragraphs, without you having to specifically write as much. This is the magic of inheritance at work. The CSS specification determines whether each property is inherited by default or not. Not all properties are inherited, but you can force ones to be by using the inherit value. Source: http://coding.smashingmagazine.com/2010/04/07/css-specificity-and-inheritance/

Descendant means anywhere nested within it in the DOM tree. Could be a direct child, could be five levels deep, it is still a descendant. This is different than a child combinator (>) which requires the element to be the next nested level down. Source: http://css-tricks.com/almanac/selectors/d/descendant/

I hope this helps

Joshua Thompson
Joshua Thompson
1,229 Points

Thank you, it does help (: I'm sure I will understand it a lot more the further I get into the CSS Deep Dive.

Neville Barrett
Neville Barrett
6,141 Points

I'm going through the CSS Deep Dive now and it's really good. Good luck.