Style paddingLeft 属性

定义和用法

paddingLeft Definition and Usage

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

and

All 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:

CSS Reference Manual:padding-left Property

HTML DOM Reference Manual:

Padding Property

Instance

Example 1

Try It Yourself

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

Example 2

Reset 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"

Property Value

Value Description
% Define left inner padding as a percentage of the parent element's width.
length Define left inner padding with 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 left inner padding of an element.
CSS Version: CSS1

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη