Style marginTop property
- Προηγούμενη σελίδα marginRight
- Επόμενη σελίδα maxHeight
- Επιστροφή στο προηγούμενο επίπεδο Όντα Style HTML DOM
Definition and Usage
marginTop
property sets or returns the top 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:CSS εξωτερικό περιθώριο
CSS Reference Manual:margin-top property
HTML DOM Reference Manual:margin property
Instance
Example 1
Set the top outer margin of the <div> element:
document.getElementById("myDiv").style.marginTop = "50px";
Example 2
Change the top outer margin of the <div> element back to "normal":
document.getElementById("myDiv").style.marginTop = "0px";
Example 3
Return the top outer margin of the <div> element:
alert(document.getElementById("myDiv").style.marginTop);
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 the marginTop property:
object.style.marginTop
Set the marginTop property:
object.style.marginTop = "%|length|auto|initial|inherit"
Attribute value
Value | Description |
---|---|
% | Define the top outer margin as a percentage of the parent element's width. |
length | Define the top outer margin with a length unit. |
auto | browser settings for the top 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 top outer margin of an element. |
CSS version: | CSS1 |
browser support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Υποστήριξη | Υποστήριξη | Υποστήριξη | Υποστήριξη | Υποστήριξη |
- Προηγούμενη σελίδα marginRight
- Επόμενη σελίδα maxHeight
- Επιστροφή στο προηγούμενο επίπεδο Όντα Style HTML DOM