使用 Bootstrap 折叠侧边栏 [英] Collapsing Sidebar with Bootstrap

查看:62
本文介绍了使用 Bootstrap 折叠侧边栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚访问了这个页面 http://www.elmastudio.de/ 并想知道是否可以使用 Bootstrap 3 构建左侧边栏折叠.

I just visited this page http://www.elmastudio.de/ and wondered if it is possible to build the left sidebar collapse with Bootstrap 3.

从顶部折叠侧边栏的代码(仅限手机):

Code to collapse the sidebar from the top (phone only):

<button type="button" class="navbar-toggle sidebar-toggle" data-toggle="collapse" data-target=".sidebar-ex1-collapse">
    <span class="sr-only">Sidebar</span>
    <span class="glyphicon glyphicon-check"></span>
</button>

侧边栏本身有 hidden-xs 类.用下面的js去掉

Sidebar itself has the hidden-xs class. It is removed with the following js

$('.sidebar-toggle').click(function(){
     $('#sidebar').removeClass('hidden-xs');            
});

如果您单击该按钮,它会从顶部切换侧边栏.很高兴看到侧边栏的行为像上面显示的网站一样.任何帮助表示赞赏!

If you click the button it toggles the sidebar from the top. It be great to see the sidebar behave like the website above shows. Any help is appreciated!

推荐答案

Bootstrap 3

是的,这是可能的.这个画布外"示例应该可以帮助您入门.

Yes, it's possible. This "off-canvas" example should help to get you started.

https://codeply.com/p/esYgHWB2zJ

基本上,您需要将布局包装在外部 div 中,并使用媒体查询在较小的屏幕上切换布局.

Basically you need to wrap the layout in an outer div, and use media queries to toggle the layout on smaller screens.

/* collapsed sidebar styles */
@media screen and (max-width: 767px) {
  .row-offcanvas {
    position: relative;
    -webkit-transition: all 0.25s ease-out;
    -moz-transition: all 0.25s ease-out;
    transition: all 0.25s ease-out;
  }
  .row-offcanvas-right
  .sidebar-offcanvas {
    right: -41.6%;
  }

  .row-offcanvas-left
  .sidebar-offcanvas {
    left: -41.6%;
  }
  .row-offcanvas-right.active {
    right: 41.6%;
  }
  .row-offcanvas-left.active {
    left: 41.6%;
  }
  .sidebar-offcanvas {
    position: absolute;
    top: 0;
    width: 41.6%;
  }
  #sidebar {
    padding-top:0;
  }
}

此外,这里有几个 更多 Bootstrap 侧边栏示例

引导程序 4

创建响应式导航栏侧边栏抽屉";在 Bootstrap 4 中?

这篇关于使用 Bootstrap 折叠侧边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆