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

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.