CSS to make HTML page footer stay at bottom of the page with a minimum height, but not overlap the page

前端 未结 29 3159
悲哀的现实
悲哀的现实 2020-11-21 23:48

I have the following page (deadlink: http://www.workingstorage.com/Sample.htm ) that has a footer which I can\'t make sit at the bottom of the page.

I wa

29条回答
  •  佛祖请我去吃肉
    2020-11-22 00:16

    One thing to be wary of is mobile devices, since they implement the idea of the viewport in an 'unusual' way:

    http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html#//apple_ref/doc/uid/TP40006509-SW25

    As such, using position: fixed; (as i've seen recommended in other places) usually isn't the way to go. Of course, it depends upon the exact behaviour you're after.

    What I've used, and has worked well on desktop and mobile, is:

    
        
    
    

    with

    body {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 0;
        margin: 0;
    }
    
    #footer {
        position: absolute;
        bottom: 0;
    }
    

提交回复
热议问题