I have been tasked with modifying the layout of a site so that it meets the criteria of the client’s corporate style guide.
The guide is requiring that I ensure certain elements are spaced [X]px from other elements, and that elements of this type are lined up with elements of that type.
So as I’m doing this, I can see that the existing spacings are defined in some cases using padding, and in other cases using margin.
Is there a preferred way of doing this? When should I use one in favour of the other?
That really depends somehow. Margin and Padding are two different things. However in some cases you will not notice a difference.
A figure which shows you the difference:
Source: http://www.edition-w3c.de/TR/1998/REC-CSS2-19980512/bilder/boxdim.gif
So for example: If you want to define the space between the border and your content you will only achieve this with padding(while having a visible border).