CSS 如何使 Bootstrap '列表组' 响应

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22295201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:03:37  来源:igfitidea点击:

How to make Bootstrap 'List group' responsive

csstwitter-bootstraptwitter-bootstrap-3

提问by Abhijith A C

I am using Bootstrap 'List group' and I need to make it responsive. Means in mobile view, The list would show as a drop down button like navbar.

我正在使用 Bootstrap ' List group',我需要让它响应。意味着在移动视图中,列表将显示为像导航栏一样的下拉按钮。

I tried nav classes, But not working as expected. Code:

我试过导航类,但没有按预期工作。代码:

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#side-menu-collapse">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
</button>    
<ul class="list-group collapse navbar-collapse" id="#side-menu-collapse">
  <li class="list-group-item dropdown-toggle">Cras justo odio</li>
  <li class="list-group-item dropdown-toggle">Dapibus ac facilisis in</li>
  <li class="list-group-item dropdown-toggle">Morbi leo risus</li>
  <li class="list-group-item dropdown-toggle">Porta ac consectetur ac</li>
  <li class="list-group-item dropdown-toggle">Vestibulum at eros</li>
</ul>

回答by BENARD Patrick

You can do this with a bit of media query. In overiding the collapseclass when the screen size is different of XS.

您可以通过一些媒体查询来做到这一点。在collapse屏幕大小不同时覆盖类XS

Bootply: https://www.bootply.com/L5BYCOwsZG

引导https: //www.bootply.com/L5BYCOwsZG

CSS:

CSS:

@media screen and (min-width: 768px) {

.custom-collapse .collapse{
            display:block;
      }  
}

HTML:

HTML:

<div class="custom-collapse">
  <button class="collapse-toggle visible-xs " type="button" data-toggle="collapse" data-parent="custom-collapse" data-target="#side-menu-collapse">
      <span class="">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
  </button> 
  <ul class="list-group collapse" id="side-menu-collapse">
    <li class="list-group-item dropdown-toggle">Cras justo odio</li>
    <li class="list-group-item dropdown-toggle">Dapibus ac facilisis in</li>
    <li class="list-group-item dropdown-toggle">Morbi leo risus</li>
    <li class="list-group-item dropdown-toggle">Porta ac consectetur ac</li>
    <li class="list-group-item dropdown-toggle">Vestibulum at eros</li>
  </ul>
</div>