Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Layout Basics Getting Started with CSS Layout Creating a Sticky Footer

Still showing the scroll bar..

p:last-child { margin-bottom: 0; }

Why is there the above code in the CSS. Can anyone explain the above code please...

1 Answer

tylerduprey
tylerduprey
24,474 Points

Hi Sandeep,

Paragraph tags have a top and bottom margin of about 1rem or 16px by default. This code tells the browser to remove the bottom margin of a paragraph if it is the last "child" of its "parent" element. In this case the <div> tag with the class "container" is the parent element. The third paragraph happens to be the "last-child" of the "container" div. So, that paragraph will not have a bottom margin because this code sets its bottom margin to "0".

Here's more about ":last-child" from CSS-Tricks: https://css-tricks.com/almanac/selectors/l/last-child/