Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap responsive affixed menu

I want to have an affixed menu as in the bootstrap doc which is not affixed on mobile phones, just as on the bootstrap doc. I've following code:

<div class="container">
  <div class="row">
    <div class="span3 bs-docs-sidebar ">
      <ul class="nav nav-list bs-docs-sidenav" data-spy="affix">
        <li><a href="#a"><i class="icon-home"></i> A</a></li>
        <li><a href="#b"><i class="icon-chevron-right"></i> B</a></li>
        <li><a href="#c"><i class="icon-chevron-right"></i> C</a></li>
      </ul>
    </div>

    <div class="span9">
      ...
    </div>
  </div>
</div>

I have tried it with and without the data-spy="affix" for the ul and I have also tried $(function(){ $('.bs-docs-sidenav').affix() }).

But the menu is always fixed so I can't read the text on mobile phones.

like image 480
white_gecko Avatar asked Nov 17 '25 12:11

white_gecko


1 Answers

I just found the answer to my question on the bootstraps doc.css file which they have on their page. You have to add following css (maybe you have to change the class if you are using the affix on a different class)

/* Tablet
------------------------- */
@media (max-width: 767px) {
  .bs-docs-sidenav.affix {
    position: static;
    width: auto;
    top: 0;
  }
}

I also just added the class affix to the bs-docs-sidenav element and didn't use any JavaScript (i.e. the data-spy)

like image 98
white_gecko Avatar answered Nov 20 '25 01:11

white_gecko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!