AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
CSS Padding |
As we saw from the box model, padding is the space just outside the content area, and just inside the border area. In a box, there are four sides. So, we can specify paddings up to the 4 sides: A fifth property, padding, is used as a shortcut for the above four properties. Paddings can be specified in two ways: length and percentage. If no value is specified, the default is 0. It is important to note that no negative values can be used for padding. Example 1 CSS declaration:
The following HTML,
renders the following:
Notice the padding between the text and the top, left, bottom, and right of the light green area are 15px, 5px, 40px, and 100px, respectively. Example 2 CSS declaration:
The following HTML,
renders the following:
Notice the padding between the text and the top, left, bottom, and right of the light green area are 15%, 5%, 20%, and 30% of the width, respectively. When using percentage with padding in this way, the percentage is expressed in terms of the width, not the height, of the box. Padding orderAll four paddings can be specified on a single line using the "padding" property. The syntax is as follows: padding: [padding-top] [padding-right] [padding-bottom] [padding-left] The order is very important here. The first element is always the top padding, the second is always the right padding, the third is always the bottom padding, and the fourth is always the left padding. If this seems hard to memorize, just remember that you start from the top and go clockwise. When only three values are specified, the first value refers to the top padding, the second value refers to the left padding and the right padding, and the third value refers to the bottom padding. When only two values are specified, the first value refers to the top padding and the bottom padding, and the second value refers to the left padding and the right padding. When only one value is specified, it refers to all four sides. Example 3 CSS declaration:
means #container3 has the following properties:
Note here that it is permissible to specify values in both legnth and percentage in the same padding declaration. Example 4 CSS declaration:
means #container4 has the following properties:
Example 5 CSS declaration:
means #container5 has the following properties:
Example 6 CSS declaration:
means #container6 has the following properties:
List of padding properties
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.