JDiMatteo JDiMatteo - 3 months ago 42
CSS Question

prevent bootstrap navbar-fixed-bottom overlap

In some cases the bootstrap navbar-fixed-bottom will overlap other content without displaying a scrollbar.

For example https://jsfiddle.net/m5vgd9g7/1/:

<div>
<a class="btn btn-primary" href="#">
Button
</a>
</div>

<div class="navbar navbar-default navbar-fixed-bottom"
style="padding-bottom:0px; min-height:0px">
bottom
</div>


If you make the display pane very short vertically, the text "bottom" overlaps the button:

enter image description here

How can the overlap be prevented, so a vertical scrollbar appears before they overlap?

Answer

You should add a class to your top div which is row, so your top html would look like

<div class="row">
  <a class="btn btn-primary" href="#">
    Button
  </a>
</div>

This will add you a scrollbar for your content vertically. But when we declare a fixed navbar you should keep in mind to add a padding/margin to the rest of the content to the size of the navbar, which should display the rest of the content without being intruded by the navbar. So your final html for the top div would look like,

<div class="row" style="padding-bottom:15px;">
  <a class="btn btn-primary" href="#">
    Button
  </a>
</div>

Note: I would never use inline styles as it would complicate the html in the long run and hard to debug. I did it here for the sake of demonstration.

And the fiddle example is here : https://jsfiddle.net/m5vgd9g7/

EDIT

Thanks to @JDiMatteo who commented about the row class addition. I was about to maintain the bootstrap standards in grid system. (ref: http://getbootstrap.com/css/#grid). Apparently it seems row should be contained within 'containerorcontainer-fluidclasses for it to work. This will define a row, where elements/columns(as in bootstrap) could reside in. And by using this, you can get rid of the custom styling we used earlier,padding/margin`.

<div class="container">
  <div class="row">
    <a class="btn btn-primary" href="#">
      Button
    </a>
  </div>
</div>
Comments