Estilo marginRight Propiedad
Ejemplo
Establecer el margen derecho de un elemento <div>:
document.getElementById("myDiv").style.marginRight = "50px";
Definición y uso
La propiedad marginRight establece o devuelve el margen derecho de un elemento.
Tanto la propiedad de margen como la propiedad de relleno insertan espacio alrededor de un elemento. Sin embargo, la diferencia es que margin inserta el espacio alrededor del borde, mientras que padding inserta el espacio dentro del borde de un elemento.
Compatibilidad con navegador
Property | |||||
---|---|---|---|---|---|
marginRight | Yes | Yes | Yes | Yes | Yes |
Sintaxis
Devuelve la propiedad marginRight:
object.style.marginRight
Establezca la propiedad marginRight:
object.style.marginRight = "%|length|auto|initial|inherit"
Valores de propiedad
Value | Description |
---|---|
% | Defines the right margin in % of the width of the parent element |
length | Defines the right margin in length units |
auto | The browser sets the right margin |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Detalles técnicos
Valor por defecto: | 0 |
---|---|
Valor devuelto: | Una cadena, que representa el margen derecho de un elemento. |
Versión CSS | CSS1 |
Más ejemplos
Ejemplo
Cambie el margen derecho de un elemento <div> a "normal":
document.getElementById("myDiv").style.marginRight = "0px";
Ejemplo
Devuelve el margen derecho de un elemento <div>:
alert(document.getElementById("myDiv").style.marginRight);
Ejemplo
Diferencia entre marginRight y paddingRight:
function changeMargin() {
document.getElementById("myDiv").style.marginRight = "200px";
}
function changePadding() {
document.getElementById("myDiv2").style.paddingRight = "200px";
}
páginas relacionadas
Tutorial CSS: Margen CSS
Referencia de CSS: propiedad margin-right
Referencia HTML DOM: propiedad de margen
❮ Objeto de estilo