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

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.