如何解决这个可折叠的bootstrap侧边栏菜单?

时间:2015-06-16 15:14:43

标签: css twitter-bootstrap-3

如果我有1个可折叠的sidemenu项目,下面的代码可以正常工作,但是当我添加另一个时,上面的项目无法正常工作。这一切都非常突出。 底部工作仍然很好。这里有什么不对,谢谢。这是bootply: http://www.bootply.com/IABXgPMp5S

<div class="container body-content">
        <div class="row row-offcanvas row-offcanvas-left">
            <!-- sidebar -->
            <div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation">
                <ul class="nav">
                    <li>
                        <a href="#" data-toggle="collapse" data-target="#sub1">Sector One </a>
                        <ul class="nav  collapse pull-right" id="sub1">
                            <li><a href="#">List 1</a></li>
                            <li><a href="#">List 2</a></li>
                        </ul>
                    </li>
                    <li>
                        <a href="#" data-toggle="collapse" data-target="#sub2">Sector Two</a>
                        <ul class="nav  collapse pull-right" id="sub2">
                            <li><a href="#">List 1</a></li>
                            <li><a href="#">List 2</a></li>
                        </ul>
                    </li>
                </ul>
        </div>
    </div><!--/.row-->
  </div><!--/.container-->

和css文件:

body {
  padding-top: 51px;  
}
.text-center {
  padding-top: 20px;
}
.col-xs-12 {
  background-color: #fff;
}
#sidebar {
  height: 100%;
  padding-right: 0;
  padding-top: 20px;
}

#sidebar .nav {
  width: 95%;
}
#sidebar li {
  border:0 #f2f2f2 solid;
  border-bottom-width:1px;
}


/* 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;
  }
}

1 个答案:

答案 0 :(得分:0)

你没有在开始第二个之前关闭第一个“ul”,所以bootstrap认为你有一个大的无序列表。 here是修复程序的链接,在此处:

<div class="container body-content">
        <div class="row row-offcanvas row-offcanvas-left">
            <!-- sidebar -->
            <div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation">
                <ul class="nav">
                    <li>
                        <a href="#" data-toggle="collapse" data-target="#sub1">Sector One <span class="glyphicon glyphicon-arrow-down pull-right"></span></a>
                        <ul class="nav  collapse pull-right" id="sub1">
                            <li><a href="#">List 1</a></li>
                            <li><a href="#">List 2</a></li>
                        </ul>
                    </li>
                </ul>
                <ul class="nav">
                    <li>
                        <a href="#" data-toggle="collapse" data-target="#sub2">Sector Two <span class="glyphicon glyphicon-arrow-down pull-right"></span></a>
                        <ul class="nav  collapse pull-right" id="sub2">
                            <li><a href="#">List 1</a></li>
                            <li><a href="#">List 2</a></li>
                        </ul>
                    </li>
                </ul>
        </div>
    </div><!--/.row-->
  </div><!--/.container-->

是更正的html