Proprietà marginLeft
- Pagina precedente marginBottom
- Pagina successiva marginRight
- Torna alla pagina precedente Oggetto Style HTML DOM
Definition and usage
marginLeft
property 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 inside the element's border.
See also:
CSS Tutorial:Margine esterno CSS
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
Change the left outer margin of the <div> element back 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
Return marginLeft property:
object.style.marginLeft
Set 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 |
Supporto | Supporto | Supporto | Supporto | Supporto |
- Pagina precedente marginBottom
- Pagina successiva marginRight
- Torna alla pagina precedente Oggetto Style HTML DOM