在移动设备上隐藏菜单中的一项

时间:2014-11-19 21:38:17

标签: twitter-bootstrap twitter-bootstrap-3

我正在使用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>

1 个答案:

答案 0 :(得分:13)

如果使用Bootstrap responsive utility classes hidden-*类,这很容易。在您的情况下,将hidden-xs添加到按钮。

<button type="button" class="navbar-toggle btn-lg hidden-xs">

示例:http://www.bootply.com/44PQOE3vg1