Style marginBottomPropiedad
Objeto Style
Definición y uso
La propiedad marginBottom establece o devuelve el margen exterior inferior de un elemento.
Sintaxis
Establecer la propiedad marginBottom:
Object.style.marginBottom="%|length|auto|inherit"
Devolver la propiedad marginBottom:
Object.style.marginBottom
| Valor | Descripción |
|---|---|
| % | Define el margen inferior como un porcentaje del ancho del elemento padre. |
| length | Define el ancho del margen inferior utilizando unidades como px, cm, etc. |
| auto | El margen inferior establecido por el navegador. |
| inherit | El margen inferior se hereda del elemento padre. |
Compatibilidad del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales admiten la propiedad marginBottom.
Nota:IE7 y versiones anteriores no admiten el valor "inherit". IE8 solo admite "inherit" si se ha especificado un !DOCTYPE. IE9 admite "inherit".
Consejos y notas
Las propiedades margin y padding insertan espacio alrededor del elemento. Sin embargo, la diferencia es que margin inserta espacio fuera del borde, mientras que padding inserta espacio dentro del borde del elemento.
Ejemplo
Ejemplo
Cambiar el margen exterior inferior de un elemento div:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<style type="text/css">
div{
border: 1px solid #FF0000;
}
</style>
<script>
function changeMargin(){
document.getElementById("ex1").style.marginBottom="100px";
}
function changePadding(){
document.getElementById("ex2").style.paddingBottom="100px";
}
</script>
</head>
<body>
<div id="ex1">Este es un texto.</div>
<br>
<button type="button" onclick="changeMargin()">Modificar el margen exterior inferior del elemento div</button>
<br>
<br>
<div id="ex2">Este es un texto.</div>
<br>
<button type="button" onclick="changePadding()">Modificar el relleno inferior del elemento div</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<style type="text/css">
div{
border: 1px solid #FF0000;
}
</style>
<script>
function changeMargin(){
document.getElementById("ex1").style.marginBottom="100px";
}
function changePadding(){
document.getElementById("ex2").style.paddingBottom="100px";
}
</script>
</head>
<body>
<div id="ex1">Este es un texto.</div>
<br>
<button type="button" onclick="changeMargin()">Modificar el margen exterior inferior del elemento div</button>
<br>
<br>
<div id="ex2">Este es un texto.</div>
<br>
<button type="button" onclick="changePadding()">Modificar el relleno inferior del elemento div</button>
</body>
</html>
Pruébalo »
Objeto Style Otras extensiones