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.

HTML How to Make a Website CSS: Cascading Style Sheets Take a Mobile-First Approach

why not select the element directly instead of creating the ID "logo"?

couldn't we have selected Header and then the anchor instead of creating the "logo" class?

2 Answers

Damien Watson
Damien Watson
27,419 Points

It is cleaner to use the 'id' and makes it easier to target the element. You could select the logo directly by doing something like the below. This will select the first direct child 'a' of header but later if the element is moved, you would have to figure out where it then sits in the hierarchy.

header > a:first-child { }

If you just did the following, you would hit all anchor tags in the header which isn't what you want either.

header a {}
Jaykuan Medina
Jaykuan Medina
4,462 Points

I feel that there is more room for error when putting the a anchor tag. its a safer bet knowing that the ID will only pick this one element instead.