Click to See Complete Forum and Search --> : CSS Margin and Padding difference


cofactor
11-30-2009, 03:06 AM
I always gets confused with CSS Margin and Padding .

suppose, I have a <div> element . Now I want to write text just after 2px down from the top ......is it Margin =2px or Padding = 2px ?

Kethinov
11-30-2009, 03:54 AM
Margin will move the div. Padding will move its contents.

Kor
11-30-2009, 03:54 AM
margin=the space outside the object (starting from "border")
padding=the space inside the object (starting from "border")

Note: and inline element (ex: SPAN) has no margin thus it can not gain any.

Your case: use padding:

See also:
http://www.w3.org/TR/CSS2/box.html