使用固定或绝对的页脚CSS

时间:2017-03-25 06:35:49

标签: html css css3

我希望我的页脚粘在底部,我在CSS下面使用:

footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    overflow: hidden;
    left: 0;
    display: block;
    right: 0;
}

我还为absolute尝试了position。它在视觉上有效,但它在移动设备上并不常用。当用户尝试触发键盘时,页脚会出现,不应覆盖键盘。

2 个答案:

答案 0 :(得分:0)

如果它覆盖了键盘,也许你应该玩一下:

z-index

答案 1 :(得分:0)

您是否使用HTML5语义?我的意思是<footer>。看看这个简单的例子:

&#13;
&#13;
footer {
  color: red;
  position: absolute;
  bottom: 0;
}
&#13;
<body>
  <header>
    <h1>HELLO</h1>
  </header>

  <footer>
    <h1>BYE</h1>
  </footer>
</body>
&#13;
&#13;
&#13;

<footer>应自动贴在页面底部。

相关问题