Proprietà marginRight
- Pagina precedente marginLeft
- Pagina successiva marginTop
- Torna al livello superiore Oggetto Style HTML DOM
Definizione e uso
marginRight
properties set or return the right outer margin of the element.
margin property and padding property All 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-right property
HTML DOM Reference Manual:margin property
Instance
Example 1
Sets the right outer margin of the <div> element:
document.getElementById("myDiv").style.marginRight = "50px";
Example 2
Changes the right outer margin of the <div> element back to "normal":
document.getElementById("myDiv").style.marginRight = "0px";
Example 3
Returns the right outer margin of the <div> element:
alert(document.getElementById("myDiv").style.marginRight);
Example 4
Difference between marginRight and paddingRight:
function changeMargin() { document.getElementById("myDiv").style.marginRight = "200px"; } function changePadding() { document.getElementById("myDiv2").style.paddingRight = "200px"; }
Syntax
Return marginRight property:
object.style.marginRight
Set marginRight property:
object.style.marginRight = "%|length|auto|initial|inherit"
Property value
Value | Description |
---|---|
% | Define the right outer margin as a percentage of the parent element's width. |
length | Define the right outer margin with a length unit. |
auto | Browser sets the right 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 representing the right 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 marginLeft
- Pagina successiva marginTop
- Torna al livello superiore Oggetto Style HTML DOM