为什么CSS位置绝对图像不显示?

时间:2015-10-18 09:20:22

标签: css

我的主容器有相对位置,我希望将2张图像叠加在一起。

当我向其中一个div添加绝对位置时,它就会消失。

我尝试使用左上角的定位等。我附上了图像的假设。

How it suppose to look

这是我的代码

  <div style="position: relative;">
    <div style="background: url('http://i.imgsafe.org/8797eaa.png') no-repeat; background-size: 100% auto; height: 709px;margin-top: 70px"></div>
    <div style="background: url('http://i.imgsafe.org/8ab6260.png') no-repeat; background-size: 100% auto; height: 170px;position: absolute; top:0; left: 0"></div>
  </div>

有什么建议吗?

2 个答案:

答案 0 :(得分:1)

使用

width:100%

对于具有绝对位置的图像将绝对解决您的问题;)

这里免费为你^^

http://jsfiddle.net/sxbo705L/1/

答案 1 :(得分:1)

你忘记了,所以指定绝对div的宽度。在css中添加width: 100%