我正在使用Bootstrap来构建菜单.当为小屏幕调整页面大小时,我会获得汉堡包图标,并显示菜单中的所有项目.有没有办法隐藏该菜单中的一个项目?我不希望我的购物车出现在汉堡包下面.我自己可以写一些jQuery代码来做到这一点,但我想知道Bootstrap是否已经有办法做到这一点?
<nav class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navMain" aria-expanded="false" aria-controls="navMain"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <button type="button" class="navbar-toggle btn-lg"> <span class="sr-only">Shopping Cart</span> <span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> </button> <a class="navbar-brand" href="#">Title</a> </div> <!-- end navbar-header --> <div id="navMain" class="navbar-collapse collapse"> <div class="navbar-collapse"> <ul class="nav navbar-nav navbar-right"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Cart </a> <ul class="dropdown-menu" role="menu"> <li><a href="#">A</a></li> <li><a href="#">B</a></li> </ul> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">My Account <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li> <div class="row" style="width: 400px;"> <ul class="list-unstyled col-md-3" role="menu"> <li><a href="#">A</a></li> <li><a href="#">B</a></li> </ul> <ul class="list-unstyled col-md-3" role="menu"> <li><a href="#">A</a></li> <li><a href="#">B</a></li> </ul> </div> </li> </ul> </li> </ul> </div> <div class="navbar-collapse"> <ul class="nav navbar-nav"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Option X <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="#">A</a></li> <li><a href="#">B</a></li> </ul> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Option Y <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="#">A</a></li> <li><a href="#">B</a></li> </ul> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li class="active"><a href="#">Option Z</a></li> </ul> </div> </div> <!-- end navMain --> </div> <!-- end container-fluid --> </nav> <!-- end container-fluid --> <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script> <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> <script src="js/ie10-viewport-bug-workaround.js"></script>
解决方法
如果您使用
Bootstrap responsive utility classes
hidden-*
课程,这很容易.在您的情况下,将hidden-xs添加到按钮.
<button type="button" class="navbar-toggle btn-lg hidden-xs">