I'm trying to re-size an image according to different browser sizes. I'm using this code:
document.getElementById("myImg").style.height = (document.body.clientHeight) * 0.5;
But it works if I'm not using DOCTYPE
, if I use DOCTYPE
in my html file, then it doesn't work. Someone said:
In using a valid DTD attribute values must have units...
So I tried to add percentage unit %:
document.getElementById("myImg").style.height = (document.body.clientHeight) * 0.5 + "%";
but it doesn't work, and it only works with px unit instead:
document.getElementById("myImg").style.height = (document.body.clientHeight) * 0.5 + "px";
How can I make work with % unit as it works with px unit? Is that even possible?