css - 是否可以在其容器背景*后面*渲染内容?

标签 css z-index css-position

再多的 z-index 技巧等也不会允许此处的单词“foo”位于 div 上的背景图像后面,对吗?

<div>
  <span>foo</span>
</div>

或者,考虑一下:

<div class="a"></div>
<div class="b">
  <span class="x">X</span>
  <span class="y">Y</span>
</div>

是否有可能.x.a后面渲染,而.y渲染前面 .a

我不知道有任何技术可以做到这一点。

注意:如果这仅适用于 Webkit,那就没问题了。

最佳答案

来自 spec :

Within each stacking context, the following layers are painted in back-to-front order:

  1. the background and borders of the element forming the stacking context.
  2. the child stacking contexts with negative stack levels (most negative first).
  3. the in-flow, non-inline-level, non-positioned descendants.
  4. the non-positioned floats.
  5. the in-flow, inline-level, non-positioned descendants, including inline tables and inline blocks.
  6. the child stacking contexts with stack level 0 and the positioned descendants with stack level 0.
  7. the child stacking contexts with positive stack levels (least positive first).

请注意,子元素始终在父元素的背景之后绘制,无论它们的 z-index 是多少。您无法让 children 在背景之前进行绘画,因此您实际上无法使用 CSS 来做到这一点。

关于css - 是否可以在其容器背景*后面*渲染内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13737014/

相关文章:

css - 按钮的背景图片不起作用

html - Z-index, block 相互叠加,这些 block 中的引用高于一切

css - 为什么具有 z-index 值的元素不能覆盖其子元素?

Modal 弹出问题中的 CSS 悬停效果

html - 绝对定位的嵌套元素上的 z-index

jquery - 如何创建从 CSS 下拉菜单到幻灯片 2 上的 iframe 的链接

html - 边框从中心插入文本

html - 文本行的确切高度(字体大小 + 行高)

css - 使用负边距时 z-index 不起作用

html - 无法将元素置于 div 内居中