So I guess CSS is not obvious to everyone. One of my coworkers asked today why you sometimes had 1 value after a "padding" attribute and sometimes you had 2 or 4 values.
Basically,
Puts a 5 pixel padding on an element.
Means you have 5 pixels of padding on the top and bottom and 3 pixels on the sides
Means you have 3 pixels of padding on top, 4 on the right, 5 on the bottom and 10 on the left.
A good way to remember this is the acronym TRBL (like "trouble").
The same applies to "margin".
As well as this, you also have extra attributes which can specify the top, bottom, right and left paddings on their own
i.e.
Sometimes, if only one side is unique, it's better to refer to it in the following way (for readability).
The "padding-left" of 10px will override the "padding" of 5px, but only on the left side of the element.
The above does the same, but is less readable in my opinion.
Basically,
padding: 5px;
Puts a 5 pixel padding on an element.
padding: 5px 3px;
Means you have 5 pixels of padding on the top and bottom and 3 pixels on the sides
padding: 3px 4px 5px 10px;
Means you have 3 pixels of padding on top, 4 on the right, 5 on the bottom and 10 on the left.
A good way to remember this is the acronym TRBL (like "trouble").
The same applies to "margin".
As well as this, you also have extra attributes which can specify the top, bottom, right and left paddings on their own
i.e.
padding-left: 10px;
Sometimes, if only one side is unique, it's better to refer to it in the following way (for readability).
padding:5px;
padding-left: 10px;
The "padding-left" of 10px will override the "padding" of 5px, but only on the left side of the element.
padding: 5px 5px 5px 10px;
The above does the same, but is less readable in my opinion.
Comments