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

why do we need to create a <div class="container"> inside <header class="main-header"> </header>

why do we need to create a <div class="container"> inside <header class="main-header"> </header>

instead, why don't we just add another class and make it like <header class = "main-header container">

Also, is there any concerns if we do not put a class on header, but simply select header in css?

1 Answer

Rune Andreas Nielsen
Rune Andreas Nielsen
5,354 Points

Hi Shung,

It's a good question and you're right that it gives the same output in the browser. The best reason I can give you is that it semantically makes more sense to create a new div with the class of container and it can enable you to create a better-structured HTML page that is easier for other people to read and maintain.

// Rune

which comes in another question... why are we putting a class in header, but not simply selecting the header on CSS to apply changes we want

Rune Andreas Nielsen
Rune Andreas Nielsen
5,354 Points

The reason is that it allows us to reuse the CSS class we made for the header on other HTML elements. Code reuse usually makes the code more readable and easier to maintain.