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

Fadi Yabroudi
PLUS
Fadi Yabroudi
Courses Plus Student 2,517 Points

Why not #gallery p {} ?

gallery p{

}

and

gallery li a p {

}

both rules select the <p> element within the 'gallery' id, so why not just use the first rule

gallery p {

}

?

If we use #gallery p {}, it will select the <p> tag inside the id "gallery".

If we use galley p {}, it will select the <p> tag wherever the tag <gallery> .

Fadi Yabroudi
Fadi Yabroudi
Courses Plus Student 2,517 Points

Selvakumar Soundararajan Excuse my syntax error, I meant to write:

#gallery p {
}

and exactly as you said if we use

#gallery p {
}

it will select the <p> tag inside the id "gallery", so why use

#gallery li a p {
} 

as the video suggests when both rules select the same <p> element ?

2 Answers

Sana Hatoum
Sana Hatoum
306 Points

We use more tags to be more specific and to write a future proof code.

gallery li a p --> Would only target the paragraphs inside anchors ....

gallery p --> would target all paragraphs that are under #gallery

While the second works fine, it might be problematic when you have to add a different style to paragraphs under gallery specifically as you'll have to rewrite both selectors.