0

what I want to achieve is a div with a background-image that reflects the size of the div, I do not care who maintain the aspect ratio

Some test

<div style='position:absolute;width:"+obj.width+"px;height:"+obj.height+"px;margin-left:"+obj.left+"px;margin-top:"+obj.top+"px;background-image:url(img.png);background-size: 100%;background-repeat: no-repeat;border:1px solid red;'>;

enter image description here

<div style='position:absolute;width:"+obj.width+"px;height:"+obj.height+"px;margin-left:"+obj.left+"px;margin-top:"+obj.top+"px;background-image:url(img.png);background-size: cover;background-repeat: no-repeat;border:1px solid red;'>;

enter image description here

<div style='position:absolute;width:"+obj.width+"px;height:"+obj.height+"px;margin-left:"+obj.left+"px;margin-top:"+obj.top+"px;background-image:url(img.png);background-repeat: no-repeat;border:1px solid red;'>;

enter image description here

WhiteLine
  • 1,919
  • 2
  • 25
  • 53

1 Answers1

2

Try this:

background-size: 100% 100%;

OR

background-size:auto 100%;
Abdulla khan
  • 758
  • 5
  • 11