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

21,945 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/