我有一个页脚,但它没有显示。这是一个http://imgur.com/cZlfyBn。所以我想要一个粘性页脚(页脚不是'固定',但保持在底部),到目前为止它被导航隐藏(我认为)。我尝试将z-index
更改为高于导航,但它仍然保持隐藏状态。代码:
HTML
<!-- Navigation -->
<div class="nav">
<div class="nContainer">
<ul class="pull-left">
<li class="active"><a>home</a></li>
<li><a href="#">about us</a></li>
<li><a href="#">contact us</a></li>
</ul>
<ul class="pull-right">
<li><a href="#">sign up</a></li>
<li><a href="#">log in</a></li>
</ul>
</div>
</div>
<!-- Collapse -->
<div class="collapse">
<h1 style="position: relative; top: 50%; transform: translateY(-50%);">Lorem ipsum dolor sit amet.</h1>
</div>
<!-- Content -->
<div class="content">
<div class="container">
<h1>Lorem Ipsum Dolor</h1>
<p>Lorem ipsum dolor...</p>
</div>
</div>
<div class="footer">
<p class="copyright">© 2015 Lorem Ipsum</p>
</div>
CSS
* {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
}
html {
position: relative;
min-height: 100%;
}
.nav {
margin-bottom: 20px;
margin-left: 0;
background-color: #fff;
height: 60px;
width: 100%;
position: fixed;
box-shadow: 0px 5px 5px #696969;
z-index: 2;
}
.nav > li > a {
display: block;
}
.pull-right {
float: right;
}
.pull-left {
float: left;
}
.nav a {
font-family: 'ABeeZee', sans-serif;
color: #b3b3ff;
padding: 14px 10px;
-webkit-transition: color 0.2s ease-in-out;
-moz-transition: color 0.2s ease-in-out;
-o-transition: color 0.2s ease-in-out;
transition: color 0.2s ease-in-out;
}
.nav a:hover {
color: #5a5a5a;
}
.nav li {
display: inline;
}
.nav .active a {
color: #5a5a5a;
cursor: default;
}
.nContainer {
margin-top: 20px;
}
.collapse {
background-image: url('http://placehold.it/1280x720');
background-size: cover;
background-repeat: no-repeat;
height: 600px;
position: fixed;
left: 0;
right: 0;
z-index: -1
text-align: center;
}
.collapse h1 {
color: #fff;
font-family: 'Shift', sans-serif;
font-size: 72px;
}
.content {
background-color: #fff;
position: relative;
top: 600px;
z-index: 1;
}
.content h1 {
color: #393c3d;
font-size: 24px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.container {
width: 90%;
}
.container {
margin-right: auto;
margin-left: auto;
*zoom: 1;
}
.container:before,
.container:after {
display: table;
line-height: 0;
content: "";
}
.container:after {
clear: both;
}
.container h1 {
margin-top: 4%;
font-family: 'Oswald', sans-serif;
font-weight: 700;
}
.container p {
font-family: 'Lato', sans-serif;
}
.footer {
height: 50px;
width: 100%;
bottom: 0;
z-index: 10;
}
答案 0 :(得分:1)
您的描述不是很清楚 - 您希望它保持在底部,但不是固定的吗?
我假设您希望它出现在内容的底部(即不固定在浏览器的底部) - 在这种情况下,您只需要移动页脚内容元素中的元素。
<!-- Content -->
<div class="content">
<div class="container">
<h1>Lorem Ipsum Dolor</h1>
<p>Lorem ipsum dolor sit amet, cons...</p>
</div>
<div class="footer">
<p class="copyright">© 2015 Lorem Ipsum</p>
</div>
</div>
答案 1 :(得分:0)
为了让z-index
起作用,你应该首先使用css定位来设置div。
所以,试试这个CSS作为你的页脚
.footer {
height: 50px;
width: 100%;
bottom: 0;
position: fixed;
z-index: 10;
}
答案 2 :(得分:0)
用以下
替换您的CSS代码.footer {
height: 50px;
width: 100%;
bottom: 0;
position: fixed.
}
您不需要:fixed
答案 3 :(得分:0)
选中此Fiddle
android:layout_below="@id/idOfTheComponentAbove"
答案 4 :(得分:0)
试试这个
* {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
}
html {
min-height: 100%;
}
.nav {
margin-bottom: 20px;
margin-left: 0;
background-color: #fff;
height: 60px;
width: 100%;
position: fixed;
box-shadow: 0px 5px 5px #696969;
z-index: 1;
}
.nav > li > a {
display: block;
}
.pull-right {
float: right;
}
.pull-left {
float: left;
}
.nav a {
font-family: 'ABeeZee', sans-serif;
color: #b3b3ff;
padding: 14px 10px;
-webkit-transition: color 0.2s ease-in-out;
-moz-transition: color 0.2s ease-in-out;
-o-transition: color 0.2s ease-in-out;
transition: color 0.2s ease-in-out;
}
.nav a:hover {
color: #5a5a5a;
}
.nav li {
display: inline;
}
.nav .active a {
color: #5a5a5a;
cursor: default;
}
.nContainer {
margin-top: 20px;
}
.collapse {
background-image: url('http://placehold.it/1280x720');
background-size: cover;
background-repeat: no-repeat;
height: 600px;
position: center bottom;
left: 0;
right: 0;
text-align: center;
}
.collapse h1 {
color: #fff;
font-family: 'Shift', sans-serif;
font-size: 72px;
}
.content {
background-color: #fff;
position: relative;
}
.content h1 {
color: #393c3d;
font-size: 24px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.container {
width: 90%;
margin-right: auto;
margin-left: auto;
}
.container:before,
.container:after {
display: table;
line-height: 0;
content: "";
}
.container:after {
clear: both;
}
.container h1 {
margin-top: 4%;
font-family: 'Oswald', sans-serif;
font-weight: 700;
}
.container p {
font-family: 'Lato', sans-serif;
}
.footer{
position: relative;
padding-top: 20px;
height: 50px;
z-index: 2;
bottom: 0;
}
&#13;
<!-- Navigation -->
<div class="nav">
<div class="nContainer">
<ul class="pull-left">
<li class="active"><a>home</a></li>
<li><a href="#">about us</a></li>
<li><a href="#">contact us</a></li>
</ul>
<ul class="pull-right">
<li><a href="#">sign up</a></li>
<li><a href="#">log in</a></li>
</ul>
</div>
</div>
<!-- Collapse -->
<div class="collapse">
<h1 style="position: relative; top: 50%; transform: translateY(-50%);">Lorem ipsum dolor sit amet.</h1>
</div>
<!-- Content -->
<div class="content">
<div class="container">
<h1>Lorem Ipsum Dolor</h1>
<p>Lorem ipsum dolor...</p>
</div>
</div>
<div class="footer">
<p class="copyright">© 2015 Lorem Ipsum</p>
</div>
&#13;