相关疑难解决方法(0)

::之前的伪元素堆叠顺序问题

当静态定位时,:: before伪元素在孩子的内容之前堆叠(z-index),但是在孩子的背景之后.任何人都可以解释为什么甚至如何发生这种情况,或者这是否是所有主流浏览器都存在的问题?

<style>
div { background-color:yellow; width:400px; }
div::before { background-color:red; content:"div::before"; }
div::after { background-color:green; content:"div::after"; }
div p { background-color:blue; color:white; margin:-15px 0; padding:0; }
</style>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sed tellus sed tellus sodales hendrerit tristique et elit.</p>
</div>
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/funkyscript/ALrgf/

css z-index pseudo-element

13
推荐指数
1
解决办法
1万
查看次数

元素的z-index对z-index的影响:before /:after伪元素

这是一个我不太了解的关于z-index和css伪元素:: before/:: after的行为.

它在这个jsfiddle上有说明:http://jsfiddle.net/jgoyon/T6QCf/

我创建了一个定位框并使用:: after伪元素添加内容(也定位).

  • 如果我将一个z-index设置为:: after伪元素,一切都运行良好我可以通过播放z-index将其放在父节点之上或之下
    #no-z-index {
      background:lightblue;
      width:100px;
      height:100px;
      position:relative;
    }
    #no-z-index:after {
      content: 'z-index -1';
      width:50px;
      height:50px;
      background:yellow;
      position:absolute;
      z-index:-1; /* z-index in question */
      top:70px;
      left:70px;
    }
Run Code Online (Sandbox Code Playgroud)
  • 如果我这样做并设置父级的z-index,它就不再起作用了.
    #z-index {
      background:lightblue;
      left:200px;
      width:100px;
      height:100px;
      position:relative;
      z-index:0; /* parent z-index */
    }
    #z-index:after {
      content: 'z-index -1';
      width:50px;
      height:50px;
      background:yellow;
      position:absolute;
      z-index:-1; /* z-index in question */
      top:70px;
      left:70px;
    }
Run Code Online (Sandbox Code Playgroud)

这是预期的行为吗?

css z-index pseudo-element css-content

7
推荐指数
1
解决办法
2340
查看次数

标签 统计

css ×2

pseudo-element ×2

z-index ×2

css-content ×1