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 Foundations The Box Model The CSS Box Model Concept

Arvid Keskitalo
Arvid Keskitalo
23,406 Points

The margin-top: 50px; does not apply as the correct code, how is that?

The div { margin-top: 50px; } does not apply as the correct code to this challenge..or how is it?

Philip Cox
Philip Cox
14,818 Points

Can you elaborate a little more please?

7 Answers

do u close div tag means '/div' in html code? or did u include an id or class in the html code? if then, u have to use it properly in the css

Arvid Keskitalo
Arvid Keskitalo
23,406 Points

code challenge: The box model Challenge task 3 of 3: : "Next, add a top margin of 50px."

I added this:

div { padding: 20px 50px; border-width: 5px; border-style: solid; margin-top: 50px; }

all applyed except the last line for the top margin, something wrong with the code?

Philip Cox
Philip Cox
14,818 Points

I cannot see anything wrong with your syntax. Unless there is conflict somewhere. Strange that it's in a challenge. It's definitely asking to apply it to the div?

Philip Cox
Philip Cox
14,818 Points

This just allowed me to complete again.

.box {padding: 20px 40px;
      border: 5px solid;
      margin-top: 50px;
 }
Arvid Keskitalo
Arvid Keskitalo
23,406 Points

Thanks Philip! I just copied your line and it went in, no problem. I don't know why, but anyway..thanks

Philip Cox
Philip Cox
14,818 Points

You're welcome. Glad it worked.

Raymon Oleaga
Raymon Oleaga
19,298 Points

I don't believe you can apply styles to a DIV, I think it should be a CLASS "." an ID "#" or a regular HTML tag like H1, P, HEADER, NAV etc......

Philip Cox
Philip Cox
14,818 Points

Hi Raymon. You can add style directly to a div element. It acts just like any other element. The issue is, you are more likely to have a lot of div's on your page, so adding class or id better represents them more specifically. :)

Raymon Oleaga
Raymon Oleaga
19,298 Points

Oh gotcha! I didnt think you could unless you added a selector like a CLASS or a and ID. Yeah I hear ya I can see how it can cause issues adding a style just to a div.

Good to now!

I also tried using margin-top: 50px and it didn't work. I looked it up and that is the correct syntax.

I took a wild guess and used the class instead of the element selector and it worked! change div { to .box {

This doesn't make much sense since they refer to the same thing! Maybe some css guru out there can explain why it works with one and not with the other.