html - 带有长文本的粘性页脚

标签 html css

我的页面中有很长的文本。我希望我的页脚贴在底部,文本应该隐藏在页脚下面,这样我就可以滚动文本。页脚下不应有文字。我怎样才能做到这一点?

.container {}
  footer {
        position: absolute;
        bottom: 0;
       }
<html>
<div class="container">
  <p>Long long text</p>
  <footer>My footer</footer>
</div>

</html>

最佳答案

您应该通过使用fixed 位置而不是absolute

来实现这一点

.container {
  padding-bottom: 40px;
}
  footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: black;
  color: white;
  padding: 10px 0;
   text-align: center;
}
<div class="container">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>

<footer>Footer Here</footer>

关于html - 带有长文本的粘性页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51171058/

相关文章:

jQuery获取多重选择的所有值,而不仅仅是选择的

html - CSS Flexbox - 在两个 div 之间居中一个 div

iPhone css悬停应该恢复正常 'unhover'

javascript - 从 Javascript 中的命名 CSS 样式获取字段

javascript - 将所有选中复选框的名称属性放入数组 - JavaScript

javascript - 将 span 标签插入 div 时出现问题

css - 并排定位 div 问题?

jQuery串行滚动: Add class to active item

java - 使用Java替换HTML页面字符串中的关键字

jquery - 隐藏字段与本地存储