Tuesday 7, September 2010
      Home       Tutorials       Free Ebooks       Free Scripts       Tech News       Articles       About Us

CSS Padding

With CSS Padding you will be able to change the default padding that appears inside various HTML elements (paragraphs, tables, etc). But first, let us make sure we understand the definition of padding. Padding is the space between an element's border and the content within it.

Example:
p {padding: 15px; border: 1px solid black; }
h5{padding: 0px; border: 1px solid red;}

This is a paragraph that has a padding of 15 pixels on every side: top, right, bottom, and left.

This header has no padding, which places the text right against the border!
There are several ways to go about defining the CSS Padding attribute. We will show you every possible way and let you know which ways are the best.

CSS Padding: 1 Value
As you saw in the example above, padding can be uniform inside an element. Specifying one value will create a uniform padding on all sides: top, right, bottom, left. In addition to using exact values, you may also define the padding with the use of percentages.

Example:
p {padding: 2%; border: 1px solid black; }
h5{padding: 0px; border: 1px solid red;}

This is a paragraph that has a padding of 5 pixels on every side: left, top, right, and bottom.
This header has no padding. It is only spaced away from the paragraph because the paragraph has a padding of 5 pixels!

CSS Padding: padding-(direction):
Each HTML element actually has 4 different paddings: top, right, bottom, and left. It is possible to define these individual paddings simply by adding a direction suffix to the padding attribute. Example form: padding-(direction). Defining only one direction will leave the other 3 default paddings untouched.

Example:
p { padding-left: 5px; border: 1px solid black; }
h5{
padding-top: 0px;
padding-right: 2px;
padding-bottom: 13px;
padding-left: 21px;
border: 1px solid red;
}

This paragraph had one padding specified(left), using directional declaration.
This header had each padding specified separately, using directional declaration.

CSS Padding: 2 & 4 Values
Four padding values can be declared at once by either specifying two or four values. When only using two values, the first will define the padding on the top and bottom, while the second will define the padding on the left and right.
When using the four value padding specification, the corresponding directions are: top, right, bottom, left. To help you remember what the order is, just remember that it starts at the top and then moves clockwise until it reaches the left. The examples below shows partial (2) and complete (4) padding usage.

Example:
p {
padding: 5px 15px;
border: 1px solid black;
}
h5{
padding: 0px 5px 10px 3px;
border: 1px solid red;
}

Example:
This paragraph has a top and bottom padding of 5 pixels and a right and left padding of 15 pixels.
This header has a top padding of 0 pixels, a right padding of 5 pixels, a bottom padding of 10 pixels, and a left padding of 3 pixels.

   
 
CSS Tutorial
 
  Introduction
Introduction
  Syntax
Syntax
  Internal CSS
Internal CSS
  External CSS
External CSS
  Inline CSS
Inline CSS
  CSS Classes
CSS Classes
  CSS Background
CSS Background
  CSS Text
CSS Text
  CSS Font
CSS Font
  CSS Border
CSS Border
  CSS Outline
CSS Outline
  CSS Padding
CSS Padding
  CSS Margin
CSS Margin
  CSS Lists
CSS Lists
  CSS Tables
CSS Tables
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download PDQCash Ebook PDQCash
   
Download Philip and Alex's Guide to Web Publishing  Ebook Philip and Alex's Guide to Web Publishing
   
Download Practical PostgreSQL  Ebook Practical PostgreSQL
   
Download Data Structures and Algorithms With Object-Oriented Design Patterns in Java  Ebook Data Structures and Algorithms With Object-Oriented Design Patterns in Java
   
Download How To Bookmark For Free Traffic Ebook How To Bookmark For Free Traffic
   
Technology News      
Studiesinn.com © 2010 All Rights Reserved.