Style paddingRight 属性

Definition and Usage

paddingRight Sets or returns the right inner padding of an element.

margin Property and padding Property They 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 Εσωτερικό Χώροι

CSS Reference Manual:padding-right Property

HTML DOM Reference Manual:padding Property

Example

Example 1

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

document.getElementById("myDIV").style.paddingRight = "50px";

Try It Yourself

Example 2

Set the right inner padding of the <div> element back to "normal":

document.getElementById("myDIV").style.paddingRight = "0px";

Try It Yourself

Example 3

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

alert(document.getElementById("myDIV").style.paddingRight);

Try It Yourself

Example 4

Difference between marginRight and paddingRight:

function changeMargin() {
  document.getElementById("myDIV").style.marginRight = "200px";
}
function changePadding() {
  document.getElementById("myDIV2").style.paddingRight = "200px";
}

Try It Yourself

Syntax

Return the paddingRight property:

object.style.paddingRight

Set the paddingRight property:

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

Property Value

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

Technical Details

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

Browser Support

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