Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi I want fit my page footer bottom of the view port when my page content height lesser than height of view port. If it exceeds it should go below that content.

i have checked height of the view port and changed that. But on some scenarios it's not working.

JavaScript
var vpHeight = getViewPort().height;
var contentHeight = $("#contentWrapper").height();

if (contentHeight < vpHeight) {
    $("#footer").css("position", "absolute");
    $("#footer").css("bottom", "0");
    $("#goToTop").hide();
}
else {
    $("#footer").css("position", "static");
    $("#footer").css("bottom", "auto");
    $("#goToTop").show();
}

function getViewPort() {
    var e = window, a = 'inner';
    if (!('innerWidth' in window)) {
        a = 'client';
        e = document.documentElement || document.body;
    }
    
    return { width: e[a + 'Width'], height: e[a + 'Height'] }
};
Posted
v2
Comments
Sergey Alexandrovich Kryukov 17-Sep-13 10:55am    
Yes, this is not so simple. I cannot find example of nice position of a footer on the sites I visit, so maybe it is not even possible to perfectly position it and have the middle part scrolling independently. Nevertheless, it makes a good question, I voted 5.
—SA

1 solution

Hi Frnds i have found answer:

Its working with some modifications.

Before:

HTML
<html>
<body>
 <div id="page">
   <div id="header"></div>
      <div id="content"></div>
    <div id="footer"></div>
 </div>
</body>
</html>


Now

XML
<html>
<body>
 <div id="page">
   <div id="header"></div>
      <div id="content"></div>
    
 </div>
<div id="footer"></div>
</body>
</html>




I have moved my footer outside from page wrapper.

Then as per browser type i have changed html,body{height:value%}.

For if IE_> height:97% means footer is fits on viewport bottom.

For Chrome and Firefox > height:97.3% and 98% respectively
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900