Style paddingLeft egenskab

定义和用法

paddingLeft Definition and usage

paddingLeft Sets or returns the left inner padding of an element. padding-left attribute margin attribute

and

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.CSS indrykning

See also:CSS Tutorial:

CSS Reference Manual:padding-left attribute

HTML DOM Reference Manual:

Padding property

Instance

Example 1

Try it yourself

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

Example 2

Restore the left inner padding of the <div> element to "normal":

Try it yourself

Example 3

Returns the left inner padding of the <div> element:

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

Try it yourself

Example 4

Difference between marginLeft and paddingLeft:

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

Try it yourself

Syntax

Return paddingLeft property:

object.style.paddingLeft

Set paddingLeft property:

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

Attribute value

Value Description
% Defined with the percentage of the parent element's width to define the left inner padding.
length Defined with length units to define the left inner padding.
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 representing the left inner padding of an element.
CSS version: CSS1

Browser support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Støtte Støtte Støtte Støtte Støtte