This is a subject that always confuses me a lot. What is the real difference between them? When to use both? I usually go through trial and error, but I need to understand how it really works.
This is a subject that always confuses me a lot. What is the real difference between them? When to use both? I usually go through trial and error, but I need to understand how it really works.
Each element in HTML is always a box.
This box has 4 area values:
padding
, in general it is transparent and little used. In the case of images, it's something like the inside of the frame. margin
. It is the frame itself from the picture frame. border
. It's the outermost part of the box. In css
, you can manipulate the properties of each part of the box with the properties:
padding
; margin
; border
; Now, when it comes to properties like top
, bottom
, left
and right
, you are changing the position of the element, and thus the base position of the element box.
If you use Chrome, you can right-click an image, and click% with%. In the right corner, you have an image of the box of the element you are inspecting.
The "top" positions the element in a coordinate, the margin-top uses the "siblings" of the object in question, just giving a space.