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 trialmohannedshehri
1,101 PointsProperties places in CSS.
Hello everyone, In this video we made a descendant selector
#gallery li a p {
margin: 0;
padding: 5%;
font-size: 0.75em;
color: #bdc3c7;
}
Can we just put "p" right after "#gallery" without "li" and "a"?
3 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Mohanned,
It would be ok to use #gallery p
given this particular markup. That will select the exact same elements as #gallery li a p
since the only paragraphs inside #gallery
are the image captions.
Ryan Gordon
1,340 PointsThat depends on your goal. This particular bit of CSS is targeting image captions. If you add p right after gallery then all the paragraph tags in the html will become stylized by this rule. If you add text later that is not an image caption, you probably won't want this rule applied to it. Furthermore, in the future, it can become difficult to find the rule causing the p tags to be stylized when you do this so broadly.
Jason Anello
Courses Plus Student 94,610 PointsHi Ryan,
It would only target all paragraphs within #gallery
. Not all paragraphs in the html.
mohannedshehri
1,101 PointsThanks for your help Jason!
Jason Anello
Courses Plus Student 94,610 PointsYou're welcome!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsTo add to this, it's not strictly necessary to list out every single descendant element on the way to the element you're trying to target.
Not sure if this specifically was what you were wondering about when asking this question.