html - 为什么 Z-index 在这里不起作用?

标签 html css positioning

<分区>

Possible Duplicate:
z-index not working with fixed positioning

我正在创建一个具有固定页眉和页脚以及固定左侧边栏的应用程序。一切正常,只是 z-index 属性不起作用。我已将页眉和页脚的 z-index 设置为 1000,将主 div 的 z-index 设置为 1。因此页眉和页脚应堆叠在 .main div 上。但是结果不一样。

<!DOCTYPE html>
<html>
  <head>
    <title>Sample Title</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>
  <body>
    <div class="header fixed-top">
      <div class="header-inner">
        <ul class="nav">
          <li>
            <a href="#">Link 1</a>
          </li>
          <li>
            <a href="#">Link 2</a>
          </li>
          <li>
            <a href="#">Link 3</a>
          </li>
        </ul>
      </div>
    </div>
    <div class="sidebar-left-fixed">This is the left sidebar. This should remain fixed.</div>
    <div class="main">And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br />And here comes the content division.
    <br /></div>
    <div class="footer fixed-bottom">
      <div class="footer-inner">footer</div>
    </div>
  </body>
</html>

还有这个 CSS:

a{
color: #777;
text-decoration: none;
text-shadow: 0 1px 0 white;
}
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 20px;
color: #333;padding:0;
margin:0;
}
ul{
margin:0;padding:0;
position:relative;
list-style-type:none;
}
li{float:left}
.nav > li > a{padding: 10px 15px 10px;}
.fixed-top{
position:fixed;
top:0;right: 0;
left: 0;
z-index:1000;
}
.fixed-bottom{
position: fixed;
right: 0;
left: 0;
margin-bottom: 0;bottom: 0;
z-index:1000;
}
.header-inner{
border-bottom:solid 1px #eee;
min-height: 40px;
z-index:1000;
position:relative;
}
.footer-inner{
border-top:solid 1px #eee;
min-height: 80px;
position:relative;
z-index:1000;
}

.sidebar-left-fixed{
position:fixed;
left:0;
width:250px;
border-right:solid 1px #eee;
height:100%;
top:40px;
}
.main{
margin-top:40px;
margin-left:250px;
margin-right:0;
min-height:600px;
border-right:solid 1px #eee;
border-bottom:solid 1px #eee;
padding:5px;
z-index:1;
position:relative;
}

注意:如果有其他好的方法可以得到这个设计,欢迎提出。

最佳答案

您没有为页眉、页脚和侧边栏部分提供任何背景颜色。否则一切正常。

关于html - 为什么 Z-index 在这里不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14118446/

相关文章:

javascript - HTML5 canvas 绘制自定义光标

jquery - 在没有 HTML5 的 Android/IOS 中触发数字键盘输入

css - 从正常流中移除并为其自身设置相对位置

html - 滚动条拒绝在 IE/Firefox 上隐藏

jQuery & CSS : Custom zoom function. .. 差不多了

php - 我的 html 表单值没有发送到 MYSQL 数据库

jquery - 如何将背景图案图像应用于 html 工具提示箭头?

jquery - 计算子 DIV + 添​​加类

html - 购物车样式 - CSS 行为

css - 使用 Z-Index 的图像叠加但看不到下面的元素