Geeks With Blogs
Woodbase Godot - Blender - .Net - C# - Game Development

I was beginning the implementation of a new design, and once again I found that my margin property on a div-tag, did not behave as I expected. So I decided to look for best practice when it comes to using margin or padding.

What I found was this very short and concise description of the difference between the two:

“Margin is on the outside of block elements while padding is on the inside.

Use margin to separate the block from things outside it, padding to move the contents away from the edges of the block.”

So what is best practice? Well it depends on the context. In my case I should have used padding…

Posted on Tuesday, June 5, 2012 2:08 PM CSS | Back to top

Comments on this post: CSS–margin or padding

# re: CSS–margin or padding
Requesting Gravatar...
Thanks for sharing. I also often get these confused.
Left by Nick Harrison on Jun 06, 2012 4:33 PM

# re: CSS–margin or padding
Requesting Gravatar...
This is a good idea to follow to be successful in my recent project. - Paradise Home Improvement Charlotte
Left by Jen Walkins on Dec 10, 2016 6:34 AM

Your comment:
 (will show your gravatar)

Copyright © woodbase | Powered by: