CSS, How to use Shorthand Margins and Padding.

Sunday, 2. August 2009

Margins create space between the edge of an element and the edge of any adjacent elements. Padding creates the space between the edge of the element and its content. The margin and padding shorthand properties also can be used to make CSS code more concise.

The margin property can combine margine-top, margin-right, margin-bottom, and margin-left. The padding property can combine padding-top, padding-right, padding-bottom, and padding-left.

The margin and padding properties also can be used to style different values for each side of an element. Values are applied in the follow order: top, right, bottom, and left – clockwise starting at the top.

The <p> element can be styled with padding-top, padding-right, padding-bottom, and padding-left or with a single padding property.

CSS Longhand

p {

color: maroon;
font: 80% arial, helvetica, sans-serif;
padding-top: 1em;
padding-right: 2em;
padding-bottom: 3em;
padding-left: 4em;

}

CSS ShortHand

p {

color: maroon;
font: 80% arial, helvetica, sans-serif;
padding: 1em 2em 3em 4em;

}