我的左侧边栏带有垂直菜单,内置“nav nav-pills nav-stacked”,当屏幕尺寸为XS(移动)时,我想要的是此菜单更改为合适的下拉菜单并开始关闭/折叠。
这是我的开始代码:
http://www.bootply.com/zOy2IJumZO
这里的html代码也是
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-3">
<div class="panel panel-info">
<div class="panel-heading">Categories <span class="badge pull-right">12345</span></div>
<ul id="categories-menu" class="nav nav-pills nav-stacked">
<li id="cid-1"><a href="automotive-vehicles">Automotive Vehicles</a></li>
<li id="cid-8"><a href="business-to-business">Business-to-Business</a></li>
<li id="cid-10"><a href="community">Community</a></li>
<li id="cid-2"><a href="electronics">Electronics</a></li>
<li id="cid-11"><a href="events">Events</a></li>
<li id="cid-12"><a href="fashion">Fashion</a></li>
<li id="cid-13"><a href="freebies">Freebies</a></li>
</ul>
</div>
<div class="panel panel-primary">
<div class="panel-heading">Site statistics</div>
<ul class="list-unstyled">
<li>1000 Users</li>
<li>200 Online</li>
<li>300 Hidden</li>
</ul>
</div>
</div>
<div class="col-xs-12 col-sm-9">
This is the right content column<br>
This is the right content column<br>
This is the right content column<br>
This is the right content column<br>
This is the right content column<br>
This is the right content column<br>
This is the right content column<br>
</div>
</div>
</div>
答案 0 :(得分:1)
使用bootstrap折叠类包装你的ul:
<div class="collapse navbar-collapse" id="collapse">
<ul id="categories-menu" class="nav nav-pills nav-stacked">
<li id="cid-1"><a href="automotive-vehicles">Automotive Vehicles</a></li>
<li id="cid-8"><a href="business-to-business">Business-to-Business</a></li>
<li id="cid-10"><a href="community">Community</a></li>
<li id="cid-2"><a href="electronics">Electronics</a></li>
<li id="cid-11"><a href="events">Events</a></li>
<li id="cid-12"><a href="fashion">Fashion</a></li>
<li id="cid-13"><a href="freebies">Freebies</a></li>
</ul>
</div>
然后将数据切换和数据目标添加到要切换菜单的元素。例如代码中的徽章12345:
<span data-toggle="collapse" data-target="#collapse" class="badge pull-right">