CSS Padding Order Example
With this example we are going to demonstrate how to use the CSS Padding property including the CSS Padding order with various examples.
1. Introduction
HTML was developed paragraph display Scientific Papers. It’s how the Web was developed to show written and formatted Monographs For the Methodology of the Scientific Work ABNT . However , with Web Evolution and Its commercial potential, it became necessary to display information with great elements of wealth Graphics and Interaction .
Then, the CSS has emerged, which is another language, separated from HTML , with sole purpose of caring for the page stylization . The CSS solves this by separating things ; style rules no longer appear in HTML , only CSS.
The css specification is maintained by the word wide web consortium (W3C). Below you can find a complete guide with values and orders for CSS Padding Property defined in w3c specification.
2.The CSS Padding Property
In ours web page, sometimes it’s neccesary organising elements in a more easy-to-read and intuitive way. When we need align or change position of one html element putting some blank space before, after or in top or botton, you must to use the CSS Padding Property.
For you chage the padding of yours html elements you can use all properties below
padding-properties.css
padding-top padding-right padding-bottom padding-left
2.1 CSS Padding Values
You can set the padding property for any html elements. In this article we will demonstrate this property in tag.
This example below is a example with out any formatting
padding-ex.html
lallalalallalallalallallalalallalallalall
lallalalallalallalallallalalallalallalall
lallalalallalallalallallalalallalallalall
lallalalallalallalallallalalallalallalall
You can especify the values off padding in many ways:
px
my-padding-px.css
.my-padding-px { padding-top: 25px; padding-right: 100px; padding-bottom: 50px; padding-left: 150px; }
my-padding-px.html
lallalalallalallalallallalalallalallalall
lallalalallalallalallallalalallalallalall
lallalalallalallalallallalalallalallalall
lallalalallalallalallallalalallalallalall
pt
my-padding-pt.html
.my-padding-pt { padding-top: 25pt; padding-right: 100pt; padding-bottom: 50pt; padding-left: 150pt; }
my-padding-pt.html
lallalalallalallalallallalalallalallalall
lallalalallalallalallallalalallalallalall
lallalalallalallalallallalalallalallalall
lallalalallalallalallallalalallalallalall
cm
my-padding-cm.css
.my-padding-cm { padding-top: 1cm; padding-right: 3cm; padding-bottom: 2cm; padding-left: 4cm; }
my-padding-cm.html
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
%
my-padding-percent.css
.my-padding-percent { padding-top: 5%; padding-right: 10%; padding-bottom: 15%; padding-left: 20%; }
my-padding-percent.html
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
2.1 CSS Padding Order
To shorten the code, it is possible to specify all the padding properties in one property. The padding property is a shorthand property for the four individual padding properties, and you need use in this order :padding-top, padding-right, padding-bottom, padding-left.
Padding property with four values
If the padding property has four values:
my-4-padding-together.css
.my-4-padding-together{ padding: 10px 20px 30px 40px; }
The order will be:
- top padding is 10px
- right padding is 20px
- bottom padding is 30px
- left padding is 40px
my-4-padding-together.html
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
Padding property with tree values
If the padding property has three values:
my-3-padding-together.css
.my-3-padding-together{ padding: 10px 20px 30px ; }
The order will be:
top padding is 10px
right and left paddings are 20px
bottom padding is 30px
my-3-padding-together.html
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
Padding property with two values
If the padding property has two values:
span style=”text-decoration: underline;”>my-2-padding-together.css
.my-2-padding-together{ padding: 10px 20px ; }
The order will be:
top and bottom paddings are 10px
right and left paddings are 20px
my-2-padding-together.html
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
Padding property with one values
If the padding property has one value:
my-padding-one.css
.my-padding-one{ padding: 10px ; }
all four paddings are 10px
my-padding-one.html
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
lallalalallalallalallallalalallalallalallall
3. Conclusion
The padding property is a shorthand property for the following individual padding properties: padding-top, padding-right, padding-bottom
and padding-left.
Κnowing the order to use it, you can improve your css, making a short code.