简体   繁体   English

页脚贴到底部

[英]Footer stick to bottom

I have bootstrap accordion in which all panels are collapsed except first one. 我有自举手风琴,除了第一个外,所有面板都折叠了。 The height of body is more than window height when the page first loads. 页面首次加载时,正文的高度大于窗口高度。 The footer is stuck to the bottom of the page initially, and it remains at the bottom if I expand another panel from accordion. 页脚最初粘在页面底部,如果我从手风琴中展开另一个面板,它仍保留在底部。 The problem is that, when all the panels are collapsed the body is of less height than the window height. 问题在于,当所有面板都折叠时,主体的高度低于窗户高度。 In this scenario the footer is not sticking to the bottom of the window, It positions in the middle of the window where accordion ends. 在这种情况下,页脚不会粘在窗口的底部,它位于手风琴结束的窗口中间。

I tried capturing the resize event, so if the body is of less height than the window then I would stick the footer to the bottom of the window else to bottom of the body, but resize doesn't work in case of accordion trigger. 我尝试捕获resize事件,所以如果身体的高度低于窗口,那么我会将页脚粘贴到窗口的底部,否则会粘到身体的底部,但是在手风琴触发的情况下调整大小不起作用。

Here is something I tried : 这是我尝试过的东西:

 $(window).resize(function(){
        footPosition();
     }); 


function footPosition()
 {var bodyHeight = $("body").height();
      var vwptHeight = $(window).height();
      if (vwptHeight > bodyHeight) {
        $("footer#pageFooter").css("position","absolute").css("bottom",0).css("width","100%");
      }else{
      $("footer#pageFooter").css("position","static").css("bottom",0).css("width","100%");
      }

}

Sorry I can't give you the accordion code, its too large. 对不起,我不能给你手风琴代码,它太大了。
But its a simple bootstrap accordion and I am stuck on this problem from last two days. 但它是一个简单的自举手风琴,我在最近两天坚持这个问题。

please help. 请帮忙。

What you're looking for is CSS Sticky Footer 您正在寻找的是CSS Sticky Footer

 <div id="footer">
    </div>

#footer {
  position: relative;
  bootom: 0;
  margin-top: -180px; /* negative value of footer height */
  height: 180px;
  clear:both;
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM