Bootstrap水平可滚动标签栏 [英] Bootstrap horizontal scrollable tab bar
问题描述
我在Bootstrap 3中创建了一个带有标签栏的应用程序。我正在动态添加和删除标签。这一切都很好,我想做的是,如果有太多的选项卡,以适应应用程序的宽度,而不是创建多个行或选项卡,有标签栏水平可滚动通过选项卡。
I am creating an app in Bootstrap 3 with a tab bar. I am dynamically adding and removing tabs. This all works great, what I would like to do though is to have the tab bar be horizontally scrollable through the tabs if there are too many tabs to fit in the width of the app instead of creating multiple rows or tabs.
有没有人做过这个或有想法如何实现这个?
Has anyone done this or have an idea how to implement this?
推荐答案
是一个示例:
(由于某种原因而不在代码段中工作,因此这里有一个指向 Bootply 的链接:http://www.bootply.com/oROUAMwsG1 )
(Not working in snippet for some reason, so here is a link to Bootply : http://www.bootply.com/oROUAMwsG1)
.nav-tabs {
overflow-x: auto;
overflow-y: hidden;
display: -webkit-box;
display: -moz-box;
}
.nav-tabs>li {
float: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="col-md-4">
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1" data-toggle="tab">Section 1</a>
</li>
<li><a href="#tab2" data-toggle="tab">Section 2</a>
</li>
<li><a href="#tab2" data-toggle="tab">Section 3</a>
</li>
<li><a href="#tab2" data-toggle="tab">Section 4</a>
</li>
<li><a href="#tab2" data-toggle="tab">Section 5</a>
</li>
<li><a href="#tab2" data-toggle="tab">Section 6</a>
</li>
<li><a href="#tab2" data-toggle="tab">Section 7</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<p>I'm in Section 1.</p>
</div>
<div class="tab-pane" id="tab2">
<p>I'm in Section 2.</p>
</div>
</div>
</div>
</div>
</div>
这篇关于Bootstrap水平可滚动标签栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!