Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.

Eric Flowers
Eric Flowers
9,472 Points

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