5 out of 13 rated this helpful - Rate this topic

padding property

Sets or retrieves the amount of space to insert between the object and its margin or, if there is a border, between the object and its border.

CSS 2.1, Section 5.5.10

Syntax

padding: <length> | <percentage>

Property values

length

Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px). For more information about the supported length units, see CSS Values and Units Reference.

percentage

Integer, followed by a %. The value is a percentage of the width of the parent object.

CSS information

Applies ToAll elements
Mediavisual
Inheritedno
Initial Value

Standards information

Remarks

This is a composite property that specifies up to four padding values, in the following order: top, right, bottom, left. If one width value is specified, it is used for all four sides. If two width values are specified, the first is used for the top and bottom borders, and the second is used for left and right borders. If three width values are specified, they are used for top, right/left, and bottom borders, respectively. Negative values are not allowed.

As of Microsoft Internet Explorer 5.5, this property applies to inline elements. With earlier versions of Windows Internet Explorer, inline elements must have an absolute position or layout to use this property. Element layout is set by providing a value for the height property or the width property.

Examples

The following examples use the padding attribute and the padding property to change the padding of the object.

This example uses td as a selector and padding1 as a class in an embedded style sheet to set the padding for the td object.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/padding_h.htm


<STYLE>
    TD { padding:3mm 8mm }
    .padding1  { padding:1cm }
</STYLE>
</HEAD> 
<BODY> 
<TABLE BORDER>
    <TD onmouseover="this.className='padding1'"
    onmouseout="this.className=''" ALIGN=middle>
    <IMG src="sphere.jpg">
    </TD>
</TABLE> 

This example uses inline scripting to set the cell's top and bottom padding to 0.5 centimeters and its left and right padding to 0.2 centimeters when an onmouseover event occurs.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/padding_s.htm


<TD onmouseover="this.style.padding='0.5cm 0.2cm'"
    onmouseout="this.style.padding=''" ALIGN=middle>
    <IMG src="sphere.jpeg">
</TD>

See also

CSSStyleDeclaration
currentStyle
defaults
runtimeStyle
style
CSS Enhancements in Internet Explorer 6

 

 

Send comments about this topic to Microsoft

Build date: 11/29/2012

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.