小编Raf*_*eca的帖子

如何使用动态高度网站将页脚保持在底部

当我有一个用CSS动态设置高度(例如从数据库获取信息)的页面时,如何将页脚div始终保持在窗口底部?


如果你想使用jQuery,我想出了这个并且工作正常:

设置页脚的CSS:

#footer { position:absolute; width:100%; height:100px; }
Run Code Online (Sandbox Code Playgroud)

设置脚本:

<script>
  x = $('#div-that-increase-height').height()+20; // +20 gives space between div and footer
  y = $(window).height();    
  if (x+100<=y){ // 100 is the height of your footer
    $('#footer').css('top', y-100+'px');// again 100 is the height of your footer
    $('#footer').css('display', 'block');
  }else{
    $('#footer').css('top', x+'px');
    $('#footer').css('display', 'block');
  }
</script>
Run Code Online (Sandbox Code Playgroud)

此脚本必须位于代码的末尾;

html css jquery footer

22
推荐指数
4
解决办法
9万
查看次数

标签 统计

css ×1

footer ×1

html ×1

jquery ×1