CSS: fixed to bottom and centered

前端 未结 9 1302
南笙
南笙 2020-11-28 04:33

I need my footer to be fixed to the bottom of the page and to center it. The contents of the footer may change at all time so I can\'t just center it via margin-left: xxpx;

9条回答
  •  执笔经年
    2020-11-28 04:50

    A jQuery solution

    $(function(){
        $(window).resize(function(){
            placeFooter();
        });
        placeFooter();
        // hide it before it's positioned
        $('#footer').css('display','inline');
    });
    
    function placeFooter() {    
        var windHeight = $(window).height();
        var footerHeight = $('#footer').height();
        var offset = parseInt(windHeight) - parseInt(footerHeight);
        $('#footer').css('top',offset);
    }
    
    
    

    Sometimes it's easier to implement JS than to hack old CSS.

    http://jsfiddle.net/gLhEZ/

提交回复
热议问题