⚠️ Warning: this is an old article and may include information that’s out of date. ⚠️
With CSS there are always various ways to accomplish something. After reading this short tidbit, you should be familiar with the various ways of controlling the size of an element’s padding, border, and margin, and you should know what the handy “clockwork” tip is, and how it will be useful to remember when you’re putting your CSS into practice.
Equal values on all four sides
If all four values (top, right, bottom, and left) are equal, then you simply write the following:
|
|
The longhand way
If you don’t want equal values on all four sides, then you can specify each side individually:
|
|
The shortcut (like clockwork)
However this seems to be quite a hassle typing out each property, so you’ll find it’s much easier to use the following shorthand, which is in this order: top, right, bottom, left (think of the hands going clockwise around a clock). The following is equivalent to the above code:
|
|
Other shorthands
This is the style I find myself writing in most often, but there are two other shorthand styles you should be aware of:
|
|
Summary
In short, there are various ways to define the padding, border, and margin on an element. Here’s a recap, with padding used as an example:
|
|
Comments