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

Jack Fitzgibbon
Jack Fitzgibbon
7,607 Points

Why do I need to add a margin?

On the video "Take a Mobile-First Approach", why do I need to add a margin of 0. The video asks me to add the following code:

#logo {
     text-align: center;
     margin: 0;
}

When I compare the element with and without a margin of 0 there is no difference; without a margin of 0 it looks the same as with a margin of 0, this is why I am wondering if this declaration is necessary. Do I need this code?

2 Answers

Gunnar Kask
Gunnar Kask
7,685 Points

Some browsers add their own margin to certain elements. Good idea is to use a reset.css file to remove those browser stylings.

When you use margin settings, like you did in the example, it overrides browser stylings. In conclusion you don't have to set margin:0 but it prevents different browser compatibility issues.

James Barnett
James Barnett
39,199 Points

> Some browsers add their own margin to certain elements

Not just some, it's all major browsers

> Good idea is to use a reset.css file to remove those browser stylings.

Instead of reset.css you should be using normalize.css, you can read more about the reasons for this choice here: http://www.cssviking.com/normalize-not-reset-css