CSS padding
padding is an area between the text (the content that element contains) and the boundary of the element. The value of the padding should always be positive. The value may be in some unit (px, em) or percentage.
<style>
.links{
color:white;
background-color:lightblue;
border:1px solid green;
}
</style>
<div style="width:100% height:auto; float:left;">
<div style="width:200px; float:left; padding:10px;"><a href="#" class="links">code</a><br><br>paddign:0px;</div>
<div style="width:200px; float:left; padding:10px;"><a href="#" class="links"style="padding:5px 10px;">strong</a><br><br>padding:5px 10px;</div>
<div style="width:200px; float:left; padding:10px;"><a href="#" class="links"style="padding:10px 20px;">bold</a><br><br>padding:10px 20px;</div>
<div style="width:200px; float:left; padding:10px;"><a href="#" class="links"style="padding:15px 30px;">italic</a><br><br>padding:15px 30px;</div>
</div>padding-top
It specifies the thickness of the padding on the top of text and the border.
<style>
div{padding-top:100px;}
</style>padding-right
It defines the padding from the right side of text (box) to the right side border.
<style>
div{padding-right:150px;}
</style>padding-bottom
It represents the padding area from the bottom side of the text (box) to the bottom border.
<style>
div{padding-bottom:100px;}
</style>padding-left
It is the padding area from the left side of the text (box) to the left side border.
<style>
div{padding-left:100px;}
</style>All of the above four properties can be written using only padding property.
<style>
div{padding:padding-top padding-right padding-bottom padding-left;}
div{padding:80px 40px 20px 5px;}
</style>padding - A shorthand property
The padding property specifies four values for four different sides. Four values are separated by spaces. The frist value for top, second for right, third for bottom and fourth value is for left side.
padding:20px; is the same as
padding:20px 20px 20px 20px;
padding:100px 50px; is the same as
padding:100px 50px 100px 50px;
padding:100px 75px 50px; is the same as
padding:100px 75px 50px 70px;
<style>
div{padding:20px;}
div{padding:100px 50px;}
div{padding:100px 75px 50px;}
</style>Examples
The padding property may be applied on all the visual elements. It may be applied on the list items, links, table heading and table data etc.
list items
The padding property is defined for the ul in the following example. The value of padding property is 15px 30px;.
<style>
.links{
color:white;
background-color:lightblue;
border:1px solid green;
}
</style>
<ul style="background-color:lightgreen; padding:15px 30px">
<li style="background-color:lightblue;">list item1</li>
<li style="background-color:lightblue;">list item2</li>
<li style="background-color:lightblue;">list item3</li>
<li style="background-color:lightblue;">list item4</li>
</ul>