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 How to Make a Website CSS: Cascading Style Sheets Take a Mobile-First Approach

Dennis de Vries
Dennis de Vries
9,440 Points

Difference between 'div;' id and 'anchor' id?

Hi everyone!

I have a question after learning to center the logo and 'wrapper' with the photo's using CSS.

To center the gallery with photo's, Nick places the photo's between a div. He then gives this an id (id="wrapper") and uses CSS to center that id.

With the logo, he basically does the exact same, except he's using the anchor-tag, giving it an id and using CSS to center it.

Both make perfect sense, both work fine and both seem to do the exact same thing. Are they the same? And why would you choose for div instead of a, or the other way around?

Thanks!

2 Answers

Alexander Smith
Alexander Smith
2,769 Points

Mainly organization. If you only have to center one thing why create a div. But, if you'll have to center multiple things it may be easier to just center their whole container(thus a div). Which is why the wrapper is a div because it's used to center the whole site.

Dennis de Vries
Dennis de Vries
9,440 Points

Great stuff, thank you Alexander.

So if I understand this correctly, I can give any tag I want an id and style that specific id in my CSS. Is that right?

Alexander Smith
Alexander Smith
2,769 Points

That's correct but remember IDs have to be unique on each page. In other words there can only be one instance of it on any page. The main advantages of IDs are internal page links and usability of with JS. If you need to style something exactly the same more than once on a page class's would be the correct choice.

Dennis de Vries
Dennis de Vries
9,440 Points

Thank you Alexander, that's all I needed (wanted) to know!