Medelwr Medelwr - 19 days ago 5
CSS Question

How to make image DOM element responsive

var img = document.createElement("img");
img.src = screenshots[i].content;
img.height = '1000';
img.width = '1000';
item.appendChild(img);


I want the height and width to be auto or % but it doesn't seem to be working with it.




I also tried

img.className = 'screenshot';

.screenshot {
height = '100%';
width = '100%';
}


With everything except setting the height and width to pixels on the DOM nothing works

Answer

You can use something like that

img
{
  width:100%;
  height:auto;
}
Comments