Style marginLeft Eigenschaft
- Vorherige Seite marginBottom
- Nächste Seite marginRight
- Zurück zur übergeordneten Ebene HTML DOM Style-Objekt
Definition and Usage
marginLeft
sets or returns the left outer margin of an element.
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 within the element's border.
See Also:
CSS Tutorial:CSS-Außenabstand
CSS Reference Manual:margin-left Property
HTML DOM Reference Manual:margin Property
Example 1
Set the left outer margin of the <div> element:
document.getElementById("myDiv").style.marginLeft = "50px";
Example 2
Revert the left outer margin of the <div> element to "normal":
document.getElementById("myDiv").style.marginLeft = "0px";
Example 3
Returns the left outer margin of the <div> element:
alert(document.getElementById("myDiv").style.marginLeft);
Example 4
Difference between marginLeft and paddingLeft:
function changeMargin() { document.getElementById("myDiv").style.marginLeft = "100px"; } function changePadding() { document.getElementById("myDiv2").style.paddingLeft = "100px"; }
Syntax
Returns the marginLeft property:
object.style.marginLeft
Sets the marginLeft property:
object.style.marginLeft = "%|length|auto|inherit"
Property Value
Value | Description |
---|---|
% | Defines the left outer margin as a percentage of the parent element's width. |
length | Defines the left outer margin with a length unit. |
auto | Browser sets the left outer margin. |
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 outer margin of an element. |
CSS Version: | CSS1 |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Unterstützung | Unterstützung | Unterstützung | Unterstützung | Unterstützung |
- Vorherige Seite marginBottom
- Nächste Seite marginRight
- Zurück zur übergeordneten Ebene HTML DOM Style-Objekt