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

Question about CSS

I was learning about CSS and I wanted to ask some questions

I wanted to ask a simple question about CSS. So, if you style a <div> element which wraps around a whole chunk of code does the style declarations you made for the <div> element apply to every single element inside?

4 Answers

Only certain properties will be inherited by descendant elements. For instance, paragraphs would inherit the color of their parent assuming they haven't already been assigned a color. Anchor links are an exception and usually would not inherit their parent color because the browser gives them a color in its style sheet.

By contrast, margins and padding would not be inherited.

Here's a table showing what can be inherited:
http://www.w3.org/TR/CSS2/propidx.html

So probably about half or less of the properties can be inherited.

Yes, unless you specify style for a particular element, class or ID within the wrapper to override.

Brad Bucceri
Brad Bucceri
7,102 Points

Yes, your CSS cascades (flows down) through your HTML. Whatever styles you apply at the highest level will be applied to the deepest nested level.

You are then able to target specific classes or id's within the parent element you talk about to apply different styles.

James Barnett
James Barnett
39,199 Points

The above answers are short but essentially correct. If you are looking for more details about inheritance in CSS check out:

http://reference.sitepoint.com/css/inheritancecascade