Style heightPropiedad
Objeto Style
Definición y uso
La propiedad height establece o devuelve la altura de un elemento.
La propiedad height solo funciona en elementos a nivel de bloque o en elementos con posición absoluta/fija. El contenido desbordante puede limitarse con la propiedad overflow.
Sintaxis
Establecer la propiedad height:
Object.style.height="auto|length|%|inherit"
Devolver la propiedad height:
Object.style.height
| Valor | Descripción |
|---|---|
| auto | Predeterminado. La altura establecida por el navegador. |
| length | Define la altura usando unidades como px, cm, etc. |
| % | Define la altura como un porcentaje del elemento padre. |
| inherit | El valor de la propiedad height se hereda del elemento padre. |
Compatibilidad del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales admiten la propiedad height.
Nota:IE7 y versiones anteriores no admiten el valor "inherit". IE8 solo admite "inherit" si se especifica !DOCTYPE. IE9 admite "inherit".
Ejemplo
Ejemplo
Establecer la altura del botón:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function displayResult(){
document.getElementById("b1").style.height="50px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="displayResult()" value="Modificar la altura del botón">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function displayResult(){
document.getElementById("b1").style.height="50px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="displayResult()" value="Modificar la altura del botón">
</body>
</html>
Pruébalo »
Objeto Style Otros recursos