2012-03-06 136 views

回答

44

你必须明确定义position属性:

.footerBox { 
    background-color: #FFFFFF; 
    border: 10px solid #DDDDDD; 
    margin: 10px 0 -200px -10px; 
    width: 1185px; 
    z-index: 1000; 

    position:relative; 

} 

http://jsfiddle.net/f2ySC/1/


这带来的页脚到current stacking context

...根元素形式根堆栈上下文。其他堆栈 上下文由具有除“ ”auto之外的'z-index'的计算值的任何定位元素(包括相对定位元素的相对 )生成。堆叠上下文不一定与包含 块有关。在将来的CSS水平,其他属性可能会引入 堆叠上下文,例如“不透明” ......

http://www.w3.org/TR/CSS2/visuren.html#z-index

+1

6年后,这仍然帮助我。谢谢! – 2018-02-20 22:56:57

0

在footerBox设置position属性absolute 你的新代码应如下所示

.footerBox { 
    background-color: #FFFFFF; 
    border: 10px solid #DDDDDD; 
    margin: 10px 0 -200px -10px; 
    width: 1185px; 
    z-index: 1000; 
    position: absolute; 
} 

看到一个演示here

我们ing position: relative也可以工作

1

这是你要找的效果吗? Updated example

我加position: relative;#footerBack.footerBox使用负保证金是不是一个好的做法,以使z-index

4

。的z-index:-1;它只是在另一个div的背景上显示内容:)

相关问题