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 CSS Basics (2014) Basic Selectors Type Selectors

top margin not going away

I set the margin to 0 and the top margin is not going away. The only way I managed to make it go away is if I set the margin 0 for all elements in the html like html, body, header and even h1!!! Whereas Guil just set the body margin to 0 and it worked fine. Why is that????????

Christopher Loyd
Christopher Loyd
Courses Plus Student 5,806 Points

Would you mind posting your CSS code so that we may assess what's wrong?

header{
    background:lightgreen;}

h1{
    margin:0;
    padding:0;
}
body{
    margin:0;
    padding:0;
}```

This is the only combination that works!

1 Answer

Germán Campos
Germán Campos
18,374 Points

I don't know every exercise by memory, but in general, every browser has default styles for things like body or forms or buttons or what have you. That's why people either go for normalize.css (a series of css rules that make the experience across browsers as close as possible to identical for starting websites) or for the simple * {padding:0; margin:0; outline:0 none;} rule.

They each have their quirks but personally, I start all my projects with the asterisk variant to ensure I'm starting from scratch, then I apply all my styles and everything is more consistent all around. But that is just my biased opinion.

Either way, for your css, I strongly suggest you order elements in terms of hierarchy, html {} should go before body {} and body{} should go before stuff like a, p, or any other specific .class or #id. That way you go from 'generic/basic' to specific, which is easier to remember/browse.

When you say 'this is the only combination that works', what other combinations did you try?

G