Style paddingTop 屬性

定義和用法

paddingTop Property sets or returns the top inner padding of an element.

The inner padding property defines the space between the element's border and its content.

margin Property and Padding Property They both insert space around the element. However, the difference is that margin inserts space around the border, while padding inserts space inside the element's border.

See Also:

CSS Tutorial:Αξία padding-top του CSS

CSS Reference Manual:padding-top Property

HTML DOM Reference Manual:Padding Property

Instance

Example 1

Set the top inner padding of the <div> element:

document.getElementById("myDiv").style.paddingTop = "50px";

Try It Yourself

Example 2

Change the top inner padding of the <div> element back to "normal":

document.getElementById("myDiv").style.paddingTop = "0px";

Try It Yourself

Example 3

Return the top inner padding of the <div> element:

alert(document.getElementById("myDiv").style.paddingTop);

Try It Yourself

Example 4

Difference between marginTop and paddingTop:

function changeMargin() {
  document.getElementById("myDiv").style.marginTop = "100px";
}
function changePadding() {
  document.getElementById("myDiv2").style.paddingTop = "100px";
}

Try It Yourself

Syntax

Return paddingTop property:

object.style.paddingTop

Set paddingTop property:

object.style.paddingTop = "%|length|initial|inherit"

Property Value

Value Description
% Top inner padding is defined as a percentage of the parent element's width.
length Top inner padding is defined by length units.
initial Sets this property to its default value. See initial.
inherit Inherits this property from its parent element. See inherit.

Technical Details

Default Value: 0
Return Value: A string that represents the top inner padding of an element.
CSS Version: CSS1

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Safari Safari Safari Safari Safari