Apa yang dimaksud dengan atribut marginLeft
- Halaman sebelumnya marginBottom
- Halaman berikutnya marginRight
- Kembali ke lapisan atas Objek 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, but the difference is that margin inserts space around the border, while padding inserts space inside the element's border.
See Also:
CSS Tutorial:Marjin luar CSS
CSS Reference Manual:margin-left Property
HTML DOM Reference Manual:Margin Property
Example 1
Sets the left outer margin of the <div> element:
document.getElementById("myDiv").style.marginLeft = "50px";
Example 2
Changes 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
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 |
Dukungan | Dukungan | Dukungan | Dukungan | Dukungan |
- Halaman sebelumnya marginBottom
- Halaman berikutnya marginRight
- Kembali ke lapisan atas Objek Style HTML DOM