Style paddingTop 属性
- Föregående sida paddingRight
- Nästa sida pageBreakAfter
- Gå tillbaka till föregående nivå HTML DOM Style Object
定义和用法
paddingTop
Sets or returns the top inner padding of an element.
The inner padding attribute defines the space between the element's border and its content.
margin property and Padding property They both insert space around the element, but the difference is that margin inserts space around the border, while padding inserts space inside the element's border.
See also:
CSS Tutorial:CSS inre kant
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";
Example 2
Change the top inner padding of the <div> element back to "normal":
document.getElementById("myDiv").style.paddingTop = "0px";
Example 3
Return the top inner padding of the <div> element:
alert(document.getElementById("myDiv").style.paddingTop);
Example 4
Difference between marginTop and paddingTop:
function changeMargin() { document.getElementById("myDiv").style.marginTop = "100px"; } function changePadding() { document.getElementById("myDiv2").style.paddingTop = "100px"; }
Syntax
Return paddingTop property:
object.style.paddingTop
Set paddingTop property:
object.style.paddingTop = "%|length|initial|inherit"
Attribute value
Value | Description |
---|---|
% | Define the top inner padding as a percentage of the parent element's width. |
length | Define the top inner padding with a length unit. |
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 |
Browserr support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Stöd | Stöd | Stöd | Stöd | Stöd |
- Föregående sida paddingRight
- Nästa sida pageBreakAfter
- Gå tillbaka till föregående nivå HTML DOM Style Object