Push footer to bottom when page is not full

前端 未结 5 1875
名媛妹妹
名媛妹妹 2021-02-13 18:58

I\'m developing a mobile web app. This is the main structure from top to bottom: header div, menu div, content div, footer div. The header, menu and footer are constant and page

5条回答
  •  名媛妹妹
    2021-02-13 19:56

    This solution worked for me. I think this is perfect if you have more than only a #header and #footer. It just push the content down with a padding-bottom if body is smaller than the viewport.

    function autoHeight() {
        var bodyHeight = $("body").height();
        var vwptHeight = $(window).height();
        var gap = vwptHeight - bodyHeight;
        if (vwptHeight > bodyHeight) {
            $("#content").css( "padding-bottom" , gap );
        } else {
            $("#content").css( "padding-bottom" , "0" );
        }
    }
    $(document).ready(function() {
        autoHeight();
    });
    $(window).resize(function() {
        autoHeight();   
    });
    

提交回复
热议问题