两个绝对定位列之间的 z 索引?
我有一个两列布局,有两个“绝对”定位的 div。
#left {
position: absolute;
top: 0;
left: 0;
z-index: 0;
}
#right {
position: absolute;
top: 0;
left: 0
z-index: 0;
}
在每一列中,我都有图像,并希望它们能够以不同的配置与 z 索引相互重叠。使用 wordpress,#left 填充来自某一类别的帖子,然后填充 #right。
是否可以将 #left 中的图像定位在 #right 中的图像之上,但不是全部?本质上 - 两个单独的 div 之间的 z 索引可以相互关联吗?
我已经为 #left 中的图像指定了高于 #right< 的 z 索引/em>,但 #right 中的图像始终位于顶部。我认为这与 #left 在代码中首先出现有关?
I have a two-column layout with two 'absolute' positioned divs.
#left {
position: absolute;
top: 0;
left: 0;
z-index: 0;
}
#right {
position: absolute;
top: 0;
left: 0
z-index: 0;
}
In each column I have images and would like them to be able to overlap one another in differing configurations with z-index. Using wordpress, #left is populated with posts from one category then subsequently, #right is populated.
Is it possible for an image from #left to be positioned above an image in #right but not all? In essence - can the z-indexes between two separate divs be relative to one another?
I have assigned z-index for images in #left higher than that of #right, but images in #right are always on top. I assume it is something to do with the fact that #left appears first in the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不会。
一旦将position:absolute放在这些容器上,每个容器都会建立自己的“堆叠上下文”,并且其中的元素将仅相对于彼此进行z轴定位。 TimKadlec.com -- 详细有关于堆叠上下文的很好的解释看看 CSS 中的堆叠
No.
Once you put position:absolute on those containers, each establishes its own "stacking context" and elements within will only be z-positioned relative to each other. There's a good explanation of stacking contexts at TimKadlec.com -- Detailed Look at Stacking in CSS
如果 div 可以选择
position:relative
那么类似这样的东西就可以工作http ://jsfiddle.net/pxfunc/ZRCke/
HTML:
CSS:
如果不是,我必须接受@SnakeFaust的答案
if it's an option for the divs to be
position:relative
then something like this could workhttp://jsfiddle.net/pxfunc/ZRCke/
HTML:
CSS:
if not I'd have to go with @SnakeFaust's answer
只是一个想法:为什么不为每个图像使用一个 div 呢?我的意思是,每个图像一个 div...
Just an idea: why don't you use a div for every image? I mean, one div per image...