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 trialArvid Keskitalo
23,406 PointsThe 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?
7 Answers
Kidist Admasu
11,020 Pointsdo 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
23,406 Pointscode 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
14,818 PointsI 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
14,818 PointsThis just allowed me to complete again.
.box {padding: 20px 40px;
border: 5px solid;
margin-top: 50px;
}
Arvid Keskitalo
23,406 PointsThanks Philip! I just copied your line and it went in, no problem. I don't know why, but anyway..thanks
Philip Cox
14,818 PointsYou're welcome. Glad it worked.
Raymon Oleaga
19,298 PointsI 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
14,818 PointsHi 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
19,298 PointsOh 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!
Bruce Gordon
6,850 PointsI 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.
Philip Cox
14,818 PointsPhilip Cox
14,818 PointsCan you elaborate a little more please?