-1

So I try to use the image like background. But for now I face the problem with dimensions of it. When I try to set the width and height by 100% I got an empty container without image.

Question - how to set image size by it's original width and height in case we do not know the size of the image before upload?

background: url(https://img.com/1000061770.jpg) no-repeat;
background-size: contain;
height: 100%; // not work
width: 100%; // not work
Max Wolfen
  • 1,923
  • 6
  • 24
  • 42

1 Answers1

1

When you set the background of an empty element it wont be seen unless the element has a width and a height

For your question, i would assume you're managing the upload of the images, so from there you can figure out the dimensions of it.

If not

var img = new Image();
img.onload = function() { alert("Width : "+img.width+ " Height : "+img.height); }
img.src = "YOUR IMG URL";

other than that if you're just going to display the image use the img tag

Rainbow
  • 6,772
  • 3
  • 11
  • 28