2011年(34)
分类: 系统运维
2011-08-18 13:28:20
The following CSS margin codes demonstrate the various CSS properties you can use to apply styles to the border of any HTML element.
Margins define the space around the element. CSS margins are specified in a similar way to borders - they can be set individually for each side, or all sides at once.
This text has a margin of 20 pixels on all four sides. It is nested within a div with a border to make it easier to see the effect of the margin.
This method uses a shorthand property for setting , , , and in the one place. This method is quicker. It also uses less code than the previous method. Actually, it's the same property that we used in our first example (i.e. the property). The only difference is that we apply multiple values against it.
Code:
This text has a different sized margin for each side. It is nested within a div with a border to make it easier to see the effect of the margin.
You don't need to provide different values for all four sides. You can provide one, two, three, or four values. Here's how it works:
If there is only one value, it applies to all sides. If there are two values, the top and bottom margins are set to the first value and the right and left margins are set to the second. If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third. If there are four values, they apply to the top, right, bottom, and left, respectively.
In other words:
margin:10px;