Ver Mensaje Individual
  #12 (permalink)  
Antiguo 01/06/2012, 08:52
natig
 
Fecha de Ingreso: enero-2007
Mensajes: 323
Antigüedad: 17 años, 4 meses
Puntos: 9
Respuesta: llamada función estilo div

Solución con JavaScript:

Código HTML:
Ver original
  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  2. <title>Documento sin título</title>
  3. <link rel="stylesheet" href="estilos_ej_java.css" type="text/css" />
  4. <script language="JavaScript">
  5. function addWidth() {
  6.     var mydiv = document.getElementById("mydiv");
  7.     var curr_height = parseInt(mydiv.style.height); // removes the "px" at the end
  8.     mydiv.style.height = (window.innerWidth * 0.2)+"px" ;
  9.    
  10. }
  11. </head>
  12.  
  13. <body onload="addWidth()" onresize="addWidth()">
  14.  
  15. <div id="mydiv" style="width:100%" ></div>
  16. </body>
  17. </html>

He cambiado screen.width por window.innerWidth y he ejecutado la función tanto al cargar como al redimensionar.

Gracias!

PD: si conocéis alguna otra manera, podéis compartirla.