CSS Padding
CSS padding specifies the space around an element inside the border. The difference of padding and margin is that the margin properties specifiy space outside the border whereas the padding properties specify space inside the border. By using CSS padding properties you can easily use space inside the border of a element. You can't use the negative values in the padding properties.
Here are the CSS padding proerties:
- padding-top - Specifies the padding at the top of an element.
- padding-bottom - Specifies the padding at the bottom of an element.
- padding-left - Specifies the padding at the left of an element.
- padding-right - Specifies the padding at the right of an element.
- padding - It is a shorthand way to declare the other padding properties.
Values Using for padding Properties
- length - The padding vaules can be defined by px, cm, pt etc.
- percentage(%) - The padding can be defined by percentage.
- inherit - The padding values will be inherited by the parent element.
Example Using All Sides padding
Example:
padding-top: 50px;
padding-bottom: 50px;
padding-left: 50px;
padding-right: 50px;
}
Run Example
The padding Property
It is a shorthand property. You can define all the padding proerties in one line by using padding property. the are several way to use the padding property.
If the padding property contains four values. Then the order will be:
- padding-top
- padding-right
- padding-bottom
- padding-left
Example:
In the example:
- padding-top: 50px
- padding-right: 30px
- padding-bottom: 60px
- padding-left: 20px
If the padding property contains three values. Then the order will be:
- padding-top
- padding-right and padding-left
- padding-bottom
Example:
In the example:
- padding-top: 50px
- padding-right, padding-left: 30px
- padding-bottom: 60px
If the padding property contains two values. Then the order will be:
- padding-top and padding-bottom
- padding-right and padding-left
Example:
In the example:
- padding-top, padding-bottom: 50px
- padding-right, padding-left: 30px
If the padding property contains one value then all four paddings get the same value.
Example:
In the example:
- padding-top, padding-bottom, padding-right, padding-left: 50px