div大小变化时,怎么让内容和背景图片的相对位置不变

我有一个DIV(A),设置了背景图片,A中有另一个DIV(B),B中有图片,位置固定

但当页面大小变化后,A的背景图片相对变化,B中的图片位置就变了

请教大神,怎么让B中的图片随着A的背景一起变化?
因为B中的图片要做一个动画效果。。设置了百分比还是不行,麻烦帮忙看看
<div style="background:url(images/bg.png) top center no-repeat; background-size: cover;width:100%;height:100%;">
<div style="position: relative; top:38%;left:0%;">
<img src="images/bg4.png" width="45%" height="34%">
<div>
<div>

第1个回答  推荐于2017-09-02
因为设置了 background-size: cover;背景图变化很不规律,试了很多方法都不行,只能把背景图和前景图切成一样大小的,而且B也只能用A的样式去写。不过这样切出的B图的文件变大
<div style="background:url(bg.jpg) no-repeat; background-size:cover; width:100%; height:100%; position:relative;">
<div style="background:url(im.png) no-repeat; width:100%; height:100%; background-size:cover; position:absolute; top:0; left:0;">

</div>
</div>本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网