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
mrx3
8,742 PointsI have a question about my margin property I used in CSS
I made a website and I have a question about where I applied my margin property. Usually I can apply a margin of zero in my footer, so the webpage appears as one. For some reason when I applied the margin 0 to the footer p:first-child the footer (line 171 of my code pen) still appeared with white space. So I inspected the webpage and found that the second p of the main-content section was causing the white-space to appear. To fix this problem I added p:nth-of-type(2) (line 159 of my code pen) with a margin of zero, and this eliminated my white-space between my footer and my main-content section. Was this the correct way to eliminate the white space. Any answers would be much appreciated, and thank you in advance.
My codepen: http://codepen.io/mike316/pen/FJvIx
1 Answer
Daniel Hurd
12,987 PointsHey Mr. X,
It is a way to correct whitespace. However, the trouble you'll find down the road is that if you ever want to add another paragraph, you'll have styling issues and you would have to remember to go to your style sheet each time to make an adjustment.
For instance, simply add one more paragraph beneath your second paragraph. You'll now need to change the nth-of-type to 3 instead of 2.
It's easier (in my opinion) to add a simple class such as the following:
```.margin-fix {
margin-bottom: 0;
}
and then add that class to your last paragraph on your site. Let me know if I can clarify anything!
mrx3
8,742 Pointsmrx3
8,742 PointsNice. Thank you Daniel.