html - 页脚不显示或粘在底部 - 隐藏在导航后面,z-index 不工作

标签 html css simple-html-dom

我有页脚,但没有显示。这是一个 example .所以我想要一个粘性页脚(不是“固定”的页脚,但停留在底部),到目前为止它被导航隐藏(我认为)。我已经尝试将 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">&copy; 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;
}

最佳答案

您的描述不是很清楚 - 您希望它留在底部,但不是固定的?

我假设您希望它出现在内容的底部(即不固定在浏览器的底部)——在这种情况下,您只需移动页脚内容元素内的元素。

  <!-- 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">&copy; 2015 Lorem Ipsum</p>
      </div>
 </div>

http://jsfiddle.net/5gqetr34

关于html - 页脚不显示或粘在底部 - 隐藏在导航后面,z-index 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31875751/

相关文章:

javascript - 如何使用增量 ID 和值多次克隆列表 "li"的元素

php - 简单的 html dom 无法打开站点的流

php - 文件获取内容(): stream does not support seeking / When was PHP behavior about this changed?

javascript - 获取 Canvas 的图像线坐标

javascript - jQuery animate scrolldown to div by <a href""> 从 1 html 到另一个 html 站点?

javascript - 图片在 HTML5 Canvas 中不显示

html - 使用 bootstrap 从 ROW 的右到左排序

javascript - 为导航选项卡应用顶部边框的最佳方法

javascript - 输入字段调整大小

php - 如何获取dom中特定类之后的所有p标签