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