Div背景图像Z-Index问题

Jon*_*Jon 21 html css

我试图让我的内容的背景图像出现在页眉和页脚的后面.目前,内容背景的顶部是伸出标题,你可以看到底部略微覆盖了页脚(注意页脚边框颜色的轻微变化).我已经尝试过设置应用于z-index:-100;有效的内容,但也使文本无法选择.然后我尝试应用于z-index:1;内容,但这并没有使内容显示在页眉/页脚下.

链接到网站

在此输入图像描述

//html
<div id="wrapper">
    <header>
        <div id="logo"></div>
        <nav>
            <ul>
                <li id="aboutNav"><a href="template.html">home</a></li>
                <li id="menuNav"><a href="">menu</a></li>
                <li id="specialsNav"><a href="">specials</a></li>
            </ul>
        </nav>  
    </header>
    <div id="content">
        content <br> goes <br> here <br>
        <a href="http://www.google.ca" target="_blank">google</a>
    </div>
</div>
<footer>
    <div id="thumbsDesc"></div>
    <div id="thumbs"></div>
</footer>



//css
header {
    width: 100%;
    height: 100px;
    background: url(../img/top.png) repeat-x;
    z-index: 110;
}

#wrapper #content {
    color: #FFFFFF;
    background: url(../img/body.png) repeat-y;
    width: 524px;
    padding: 25px 30px 25px 30px;
    position: absolute;
    bottom: 100px;
    top: 90px;
    margin: 0 0 0 150px;
    z-index: 1;
}

footer {
    margin: -107px 0 0 0;
    width: 100%;
    height: 107px;
    background: url(../img/bottom.png) repeat-x;
    z-index: 100;
}
Run Code Online (Sandbox Code Playgroud)

Zuu*_*uul 61

要解决此问题,您在页脚和页眉上使用z-index,但是忘记了位置,如果要使用z-index,则元素必须具有以下位置:

添加到您的页脚并标题此CSS:

position: relative; 
Run Code Online (Sandbox Code Playgroud)

编辑:

还注意到#backstretch上的背景图片有一个负的z-index,不要使用它,有些浏览器真的很奇怪......

从#backstretch中删除:

z-index: -999999;
Run Code Online (Sandbox Code Playgroud)

在这里阅读一些关于Z-Index的内容!

  • 为@Zuul救了另一个生命:我的生命.谢谢! (2认同)

Ste*_*eve 7

为了让 z-index 起作用,你还需要给它一个位置:

header {
    width: 100%;
    height: 100px;
    background: url(../img/top.png) repeat-x;
    z-index: 110;
    position: relative;
}
Run Code Online (Sandbox Code Playgroud)