html - z-index - 标志在标题后面

标签 html css

我正在制作一个网站,但即使 z-index 设置得更高,我的 Logo 仍位于页眉后面。我不知道为什么?我已经设置了定位,为什么它不起作用?叠加层都是透明的 .png s,因为我想让它与所有浏览器兼容,而 RGBa 不是。

Photo of the problem

CSS 是:

@charset "utf-8";

body {
    margin-left: 0px;
    margin-right:0px;
    margin-top: 0px;
    padding:0px;
    z-index:-101;
}

#wrapper{
    margin-left:17.3875%;
}

#BG {
    height: auto;
    width: 100%;
    position: fixed;
    z-index: -100;
    left: 0px;
    top: 0px;
    min-height: 100%;
    min-width: 1040px;
}
/*HEADER*/
/*===================================================================*/
#header{
    margin:0px;
    padding:0px;
    z-index:-98;
    position:fixed;
    z-index:-99;
    width:65.225%;
    height:18.2022472%;
    background:url(WireFrame/Nav%20Bar.png)
}

.logocontainer{
    width:34.1510157%;
    height:100%;
    margin:0;
    padding:0;
    z-index:-1;
    position:absolute;
    }

.logoimage{
    max-height:100%;
    max-width:100%;
    z-index:1;
    position:absolute;
}

#navigation{

}
/*BODY*/
/*===================================================================*/
#bodyoverlay{
    background:url(WireFrame/Body.png);
    position:fixed;
    z-index:-99;
    height:100%;
    width:65.225%;
    background-repeat:repeat-y
}

#body{
    z-index:-98;
    height:100%;
    width: 100%;

}

html 是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home</title>
<link href="CSS.css" rel="stylesheet" type="text/css" />
</head>

<body>
<img src="file:///U|/Year 8/ICT/Webdesign/WireFrame/Background.jpg" name="BG" width="4000" height="2670" id="BG" />
<div id = "wrapper">
    <header>
    <div id = "header">
        <div class="logocontainer">
        <img src="WireFrame/Logo.png" class="logoimage" />        </div>
        <nav>
            <div id = "navigation">         </div>
        </nav>
    </div>
    </header>
    <!---->
    <div id = "body">
        <div id = "bodyoverlay">
        </div>
        <div id = "Content">
        </div>
    </div>
</div>
</body>
</html>

最佳答案

您使用 z-index 属性的方式有很多问题:

  • 首先,您必须为每个具有 z-index 的元素定义一个 position
  • 其次,z-index 不会对页面中的所有内容进行绝对排序——存在不同的堆叠上下文。
  • (您在#header 中也有多个z-index)

这是 an excellent article on z-index that everyone should read这有望帮助您解决代码中的问题。

关于html - z-index - 标志在标题后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22668876/

相关文章:

javascript - 左键点击激活oncl​​ick 右击激活href

html - 如何在 ionic 2 中制作高度响应屏幕?

java - Java 中的 xhtml 到 pdf 转换中的数学方程支持

php - 仅向 super 管理员显示 css

javascript - 如何在 <hr> 上制作小箭头按钮(用于 JQuery 的 slideUp/slideDown)

css - 使用 bootstrap 在悬停时切换到 glyphicons-white

html - word-wrap : break-word and word-break: break-word之间的区别

html - 鼠标点击时 Div 隐藏/显示的问题

javascript - 在网页之间传递大量数据

css - 响应式页面 - 溢出问题