Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

auto left and right padding blocks top and bottom padding

I am a beginner to CSS and I see a strange problem.

I want to add top and bottom padding to my footer. I can of course use the padding-top and padding-bottom separately but I would like to use the padding property.

If I use padding: 45px auto for my footer, the top and bottom padding do not apply.
Whereas if padding: 45px 0 is used for the footer, the top and bottom padding works fine.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What’s wrong? I have already checked the padding MDN page and it does not even have mention of auto 🙁

Please help.

footer {
  border: 1px dotted grey;
  text-align: center;
  padding: 45px auto;
  padding: 45px 0;
}
<html>
<body>
    <footer>
        <p>&copy; 2024 Footer Text</p>
    </footer>
</body>
</html>

>Solution :

Padding can’t have auto as value, that’s invalid.

If you just want to set top and bottom, you need to use padding-top/-bottom.

If you want to center your elements left/right:

footer{
    display: flex; 
    justify-content: center;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading