我想要实现的是一个带有背景图像的div,它反映了div的大小,我不关心谁保持宽高比
<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;'>;
<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;'>;
<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;'>;
答案 0 :(得分:2)
试试这个:
background-size: 100% 100%;
OR
background-size:auto 100%;