CSS padding


Home - Tutorials - CSS tutorials

In this article I will show you how to use the CSS padding attribute in your website projects.

Tutorial info:


Name:CSS padding
Total steps:1
Category:CSS tutorials
Date:2008-04-02
Level:Beginner
Product:See complete product
Viewed:633

Bookmark CSS padding



AddThis Social Bookmark Button

Step 1 - CSS padding


CSS padding

CSS padding definition 

The CSS padding property defines the space between the element border and element content.

Don't forget that the default padding values could be different from browser to browser.

 

Usage 

You can define CSS padding property in more ways. 

Here is an example how you can do this:

Code:
  1. .test {
  2. padding: 4px;
  3. }
  4.  
  5. .test2 {
  6. padding: 2px 4px;
  7. }

You can define the 4 different value at once or one by one with the dedicated property. If you define all 4 CSS padding values at once then the order is the following:

Quite simple to remember: clockwise, starts from midnight :)

Code:
  1. .test3 {
  2. padding: 2px 4px 6px 8px;
  3. }
  4.  
  5. .test4 {
  6. padding-top: 4px;
  7. padding-right: 6px;
  8. padding-bottom: 8px;
  9. padding-left: 10px;
  10. }

 

CSS padding example

Code:
  1. <html>
  2. <head>
  3. <title>CSS padding</title>
  4. </head>
  5. <body>
  6. <p style="padding:5px;border:1px solid;">
  7. This is a 5 pixel padding for all side.
  8. </p>
  9.  
  10. <p style="padding:2px 10px;border:1px solid;">
  11. This is a 2 pixel on top and bottom and 10px left and right.
  12. </p>
  13.  
  14. <p style="padding:2px 4px 6px 8px;border:1px solid;">
  15. All paddings are different
  16. </p>
  17.  
  18. <p style="padding:0px;border:1px solid;">
  19. No padding at all.
  20. </p>
  21. </body>
  22. </html>
  23.  

And the output is:

This is a 5 pixel padding for all side.

This is a 2 pixel on top and bottom and 10px left and right.

All paddings are different

No padding at all.






Tags: css padding property, css padding, css, padding

CSS padding - Table of contents
Step 1 - CSS padding

F1 Site Family
AJAX F1
CSS F1
Database F1
Forex F1
Flash F1
HTML F1
JavaScript F1
PhotoShop F1
PHP F1
 

 
MaxTutorial
Monthly mortgage payment calculator
WebFormGenerator
Forex mini accounts

Total time: 0.1087