|
Quick Menu
|
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. A padding is the space between an element's border and the content within it. Setting the actual value of padding is just the same as with margin, so you can probably zip right through this lesson as well.
CSS Code
p {padding: 15px; border: 1px solid black; }
h5{padding: 0px; border: 1px solid red;}
How It Looks
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!
|
|
|
|
Site Stats
| There are 5 users online | | click to see where | | 149,437 total unique visitors | | 486,656 total pageviews | | 63 visitors in the last 24 hours | | 61 total visitors today | | 218 pageviews today | | This page has been visited 909 times
| | get this script | | Most users online at once: 63 on 01/18/2010 |
|
|
|
|
|
|
There are several ways to go about defining the css padding attribute. We will show you how they are done with the most common ways and let you decide which methods are the best for you.
SINGLE 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.
CSS Code
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!
|
PADDING DIRECTIONS
Each HTML element actually has 4 different padding's: top, right, bottom, and left. It is possible to define these individual padding's simply by adding a direction suffix to the padding attribute. Example form: padding-(direction). Defining only one direction will leave the other 3 default padding's untouched.
CSS Code
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.
|
PADDING MULTIPLE 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 left and right, while the second value will define the padding on the top and bottom.
When using the 4 value padding specification, the corresponding directions to values 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.
CSS Code
p {padding: 5px 15px;
border: 1px solid black; }
h5{padding: 0px 5px 10px 3px;
border: 1px solid red;}
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.
|
Its basically the same as adding margins except its adding it on the inside of the element, not around the outside of it.
|