Saturday 21 December 2013

CSS » Padding



The CSS padding properties define the space between the element border and the element content.

In this tutorial we will show You how to set left, right, bottom and top padding. After this we will show You how to use the shorthand property(all in one).

There's two possible values - length( in pixels, pt, em, etc. ) and  % ( Defines a padding in % of the containing element ).












Individual Sides

You can specify different padding for different sides.


» EXAMPLE:


<html>

<head>
<style>
.demo {
background-color: #03C;
color: #FFF;
}
#padd {
padding-top: 30px;
    padding-bottom: 30px;
    padding-right: 20px;
    padding-left: 20px;
}
</style>
</head>
<body>
<h3 class="demo">This is heading with default padding.</h3><br />
<p id="padd" class="demo">This is paragraph with ready padding.</p>
</body>
</html>


» Result:




This is heading with default padding.


This is paragraph with ready padding.





Shorthand property

Now You will see how to use all CSS padding properties in one property.

» EXAMPLE:

<html>
<head>
<style>
.demo {
background-color: #03C;
color: #FFF;
}
#padd {
padding: 30px 20px;
}
</style>
</head>
<body>
<h3 class="demo">This is heading with default padding.</h3><br />
<p id="padd" class="demo">This is paragraph with ready padding.</p>
</body>
</html>


» Result:

This is heading with default padding.


This is paragraph with ready padding.





The padding property can have from one to four values.
  • padding:25px 50px 75px 100px;
    • top padding is 25px
    • right padding is 50px
    • bottom padding is 75px
    • left padding is 100px

  • padding:25px 50px 75px;
    • top padding is 25px
    • right and left paddings are 50px
    • bottom padding is 75px

  • padding:25px 50px;
    • top and bottom paddings are 25px
    • right and left paddings are 50px

  • padding:25px;
    • all four paddings are 25px

No comments:

Post a Comment