1. Computing & Technology

Discuss in my forum

Using Shorthand Notation with CSS margin, padding, and border Styles

By , About.com Guide

When using the shorthand versions of certain CSS properites like margin, padding, and border, you put the rule in the order
top right bottom left

But if you leave off certain numbers you can have more control:

margin: 0px;
defines all margins as 0px.

padding: 10px 5px;
defines the top and bottom padding as 10px each and the right and left padding as 5px each.

border-width: 1px 5px 2px;
defines the top border as 1px, the right and left border as 5px and the bottom border as 2px.

margin: 1px 10px 5px 3px;
the standard usage, defining the top as 1px, the right as 10px, the bottom as 5px, and the left as 3px.

©2012 About.com. All rights reserved.

A part of The New York Times Company.