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 trialStuart Howell
2,021 Pointsgallery 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
Treehouse Moderator 91,253 PointsI 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
2,021 PointsStuart Howell
2,021 PointsThanks for the answer, so gallery li a p is a child element of gallery li, so won't overwrite it?
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsThat's right, HTML elements have a "parent/child" relationship.
So if you look at a structure like this
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
2,021 PointsStuart Howell
2,021 PointsPerfect, thank you! :)