最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap responsive affixed menu - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Nov 24, 2012 at 14:46 white_geckowhite_gecko 5,0865 gold badges59 silver badges88 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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)

发布评论

评论列表(0)

  1. 暂无评论