我正在创建一个具有固定页眉和页脚以及固定左侧边栏的应用程序。除了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;
}
注意:如果有其他好方法可以获得此设计,欢迎使用。
答案 0 :(得分:1)
您的页眉,页脚和侧边栏部分没有任何背景颜色。否则它工作正常。
答案 1 :(得分:0)
它似乎工作,唯一的事情是你的页眉/页脚没有任何背景(颜色)。透明,你只需通过它看到内容。
如果您在页眉和页脚中添加背景颜色,则可以看到其下的内容。
答案 2 :(得分:0)
我认为morksinaanab有正确的,但您也可以在.main中添加padding-bottom。 尝试添加:
.main {
/* Your code */
padding-bottom: 85px; } /* the height of padding should be at least the same amount that footer height + 5px for space */