Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将页脚粘贴到页面底部_Html_Css_Footer_Sticky Footer - Fatal编程技术网

Html 将页脚粘贴到页面底部

Html 将页脚粘贴到页面底部,html,css,footer,sticky-footer,Html,Css,Footer,Sticky Footer,我如何制作一个页脚,它会粘在页面底部,并随着我的内容移动?我尝试过使用位置,但是当屏幕上的内容超过了屏幕所能容纳的范围时,页脚会停留在屏幕底部,而内容会覆盖在其顶部。如果使用: position:fixed; bottom:0px; 那应该可以 宽度:100%如果你需要的话。我会为页脚创建css类- footer.bottom { position: fixed; bottom: 0px; } 与jQuery相比 if ( $(document).height() <

我如何制作一个页脚,它会粘在页面底部,并随着我的内容移动?我尝试过使用
位置
,但是当屏幕上的内容超过了屏幕所能容纳的范围时,页脚会停留在屏幕底部,而内容会覆盖在其顶部。

如果使用:

position:fixed;
bottom:0px;
那应该可以


宽度:100%如果你需要的话。

我会为页脚创建css类-

footer.bottom {
    position: fixed;
    bottom: 0px;
}
与jQuery相比

if ( $(document).height() < $(window).height() ) {
    $('footer').addClass('bottom');
} else {
    $('footer').removeClass('bottom');
}
if($(文档).height()<$(窗口).height()){
$('footer').addClass('bottom');
}否则{
$('footer').removeClass('bottom');
}

所以,如果body比window短,它会添加类,使其与bottom保持一致,但如果body比window高,那么这将是正常的。

我想您使用div来制作页脚。您是否尝试过
z-index
CSS属性?较大的
z索引将导致元素出现在前面


只是一个尝试的建议。

这个方法解决了我的问题。我认为它应该解决所有与粘性页脚相关的问题。谢谢大家回答我的问题

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
footer.bottom {
    position: fixed;
    bottom: 0px;
}
</style>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script>
$(document).ready(function(){
if ( $('#x')[0].scrollHeight < $(window).height() ) {
    $('footer').addClass('bottom');
} else {
    $('footer').removeClass('bottom');
}
});
</script>
</head>
<body>
<div id="x">
<table height="1000" bgcolor="#999999">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

    <footer>
    Lorem Ipsum
    </footer>

</div>
</body>
</html>

页脚底部{
位置:固定;
底部:0px;
}
$(文档).ready(函数(){
if($('#x')[0]。滚动高度<$(窗口).height(){
$('footer').addClass('bottom');
}否则{
$('footer').removeClass('bottom');
}
});
乱数假文

show fiddle of which your tried this is replicated here:-你搜索过这个吗?为什么在这么多常见问题解答和帮助主题之后,为什么会提出一个不完整的问题。我们不能在这里建立一个完整的页面。为什么连答案都会不断弹出:\n但我需要页脚,页脚应该始终位于内容之后。位置:页面上的固定页脚将始终固定。请阅读完整的问题:“我尝试使用位置。但当内容超过显示器高度时,页脚上的内容将被覆盖。”