提问者:小点点

元素之间的背景位置


我想知道第二个div背景是否可能在我的下一个div中也可见。

<div style="max-width:100%;width:100%;">
...
</div>
<div style="max-width:100%;width:100%; background:url('someimage.png')">
...
</div>
<div style="max-width:1200px; width:100%">
...
</div>

或者我必须使用image并绝对定位它:

<div style="max-width:100%;width:100%;">
...
</div>
<div style="max-width:100%;width:100%;position:relative;z-index:2">
...
</div>
<img src="someimage.png" style="position:absolute;width:100%;height:300px;z-index:1" />
<div style="max-width:1200px; width:100%;position:relative;z-index:2;">
...
</div>

但是在图像的情况下,我将无法正确地定位它相对于第二个div。

除非有别的方法?


共1个答案

匿名用户

  1. 您需要在div和img中定义位置
  2. img需要位置:绝对

您需要在div和img中定义位置。Img需要位置:绝对。但如果需要设置背景,更好的解决方案是背景图像属性。