0

I'm trying to create a footer that stays below the page content and sticks to the bottom of the page. I've tried applying Twitter Bootstrap 3 Sticky Footer to my page, but it causes the footer to stick to the bottom and overlap the page content (if the page is too short).

I'm currently using the css:

html {
    position: relative;
    min-height: 100%;
}
body {
    margin-bottom: 348px;
}
.footer {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 348px;
}

and the html: (simplified)

<body>
   <!-- Navigation -->
  <div class="wrapper">
    <div class="container"
    page content
    </div>
  </div>
<footer class="footer navbar-fixed-bottom">
  <!-- Footer-->
</footer>
</body>

and the footer is now sticking to the bottom, but when the page is very narrow, you can see through to the background instead of the footer background covering it.

Image

Any help in resolving this would be greatly appreciated.

Community
  • 1
  • 1
huhn
  • 27
  • 5
  • Do you have a link to a 'short' page? Ah, it also doesn't work properly when the page isn't very short. – KIKO Software Apr 13 '17 at 06:10
  • Your page seems fine? where is the sticky footer in the link you specified? More over i wouldnt recommend making a 348px tall footer `sticky` !! – Jones Joseph Apr 13 '17 at 06:13
  • @JonesVinothJoseph The black footer at the bottom. https://i.stack.imgur.com/LrWe5.png When the page is narrow this happens. – huhn Apr 13 '17 at 06:18

2 Answers2

1

Problem is with the height. Just remove the height from footer then it will be fine.

html {
    position: relative;
    min-height: 100%;
}
body {
    margin-bottom: 348px;
}
.footer {
    position: absolute;
    bottom: 0;
    width: 100%;
}

<!----html---->
<body>
    <!-- Navigation -->
    <div class="wrapper">
        <div class="container">page content</div>
    </div>
   <footer class="footer navbar-fixed-bottom"></footer>
</body>
Jones Joseph
  • 4,703
  • 3
  • 22
  • 40
sneha
  • 435
  • 4
  • 9
1

Seeing that you have used jQuery. Along with removing the height from footer, a simple resize() event can decide the correct margin-bottom.

$(window).resize(function(){
    var xHeight = $('.footer').height();
    $('body').css('margin-bottom',xHeight + 'px');
})

Hope this helps

Jones Joseph
  • 4,703
  • 3
  • 22
  • 40