【问题标题】:Build responsive navbar using bootstrap which collapses to an aside nav bar?使用折叠到旁边导航栏的引导程序构建响应式导航栏?
【发布时间】:2014-09-16 11:41:51
【问题描述】:

如何在 Twitter Bootstrap 3 中构建一个响应式导航栏,该导航栏在移动设备中折叠为侧边导航菜单?

我知道如何使用当前 Bootstrap 版本附带的响应式导航栏,但我想实现类似下面链接中给出的其他功能!

http://grainandmortar.com/

【问题讨论】:

    标签: twitter-bootstrap navigation


    【解决方案1】:

    基本上你可以这样做:

    HTML 结构:

    <div class="row row-offcanvas row-offcanvas-right">
        <div class="col-xs-12 col-sm-9">
            <p class="pull-right visible-xs">
                <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas">Toggle nav</button>
             </p>
        </div>
    
        <div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation">
            <div class="list-group">
                <a href="#" class="list-group-item active">Link</a>
            </div>
        </div>
    </div>
    

    CSS:

    html,
    body {
      overflow-x: hidden; /* Prevent scroll on narrow devices */
    }   
    
    /*
     * Off Canvas
     * --------------------------------------------------
     */
    @media screen and (max-width: 767px) {
      .row-offcanvas {
        position: relative;
        -webkit-transition: all .25s ease-out;
             -o-transition: all .25s ease-out;
                transition: all .25s ease-out;
      }
    
      .row-offcanvas-right {
        right: 0;
      }
    
      .row-offcanvas-left {
        left: 0;
      }
    
      .row-offcanvas-right
      .sidebar-offcanvas {
        right: -50%; /* 6 columns */
      }
    
      .row-offcanvas-left
      .sidebar-offcanvas {
        left: -50%; /* 6 columns */
      }
    
      .row-offcanvas-right.active {
        right: 50%; /* 6 columns */
      }
    
      .row-offcanvas-left.active {
        left: 50%; /* 6 columns */
      }
    
      .sidebar-offcanvas {
        position: absolute;
        top: 0;
        width: 50%; /* 6 columns */
      }
    }
    

    jQuery;

    $(document).ready(function () {
      $('[data-toggle="offcanvas"]').click(function () {
        $('.row-offcanvas').toggleClass('active')
      });
    });
    

    看看这个引导模板,看看它的实际效果。

    Bootstrap Offcanvas Menu

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 1970-01-01
      • 2014-12-14
      相关资源
      最近更新 更多