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

Set margin to <p> but only in a specific element?

Hi Treehouse!

I'm trying to adjust the top and bottom margins to the <paragraph> text in my footer but I don't want to change the margins of the other <paragraph> in my code, that is to the <paragraph> in the rest of the site <body>.

I this possible at all? Does anybody know how to make this happen?

1 Answer

Steven Parker
Steven Parker
243,656 Points

This can be easily done with a "descendant selector". This one will apply only to paragraphs inside the footer:

footer p {
    margin: 5px 0;  /* substitute your actual desired settings */
}

You might enjoy the CSS Selectors course.

That's actually what I tried but I might have missed something earlier.

Thank you so much, Steven! And thanks for the tip about CSS Selectors course.

If the footer is a div, can I still do this? Or is that the problem for me here?

Like:

.footer p { margin: 5px 0; /* substitute your actual desired settings */ }

Steven Parker
Steven Parker
243,656 Points

That should work just as well.