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

HTML How to Make a Website Styling Web Pages and Navigation Style the Image Captions

Stuart Howell
Stuart Howell
2,021 Points

gallery li a p selector question

In gallery li a p selector, surely the margin: 0 overwrites the margin: 2.5% in gallery li selector above it?

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

I think specificity plays a part here, and the element structure in your HTML.

the paragraph is the primary element here. We want list items to have a margin but we don't want this for the paragraphs or the links inside them, so we do want to override that property. The list item will retain its margin but instead of inheriting the same value the child elements will lose the value altogether. :-)

Stuart Howell
Stuart Howell
2,021 Points

Thanks for the answer, so gallery li a p is a child element of gallery li, so won't overwrite it?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

That's right, HTML elements have a "parent/child" relationship.

So if you look at a structure like this

<div>
    <p><span></span></p>
    <h2></h2>
<div>

Div is the parent element of p and h2. Whereas p is a child element of div but a parent element of span And h2 is a sibling element to p. :-)

Stuart Howell
Stuart Howell
2,021 Points

Perfect, thank you! :)