当第二导航丸活跃时,Bootstrap导航丸 - 第一个导航丸数据仍然存在

时间:2016-06-15 06:49:38

标签: javascript jquery html twitter-bootstrap nav-pills

我正在使用Bootstrap药丸在同一页面上切换。有两个导航丸和两个div对应每个。我已经正确构建了第一个div并且工作正常。但是当我试图构建第二个div时,第一个div的内容阻碍了第二个div的构建。例如:col- *类不能正常工作。简而言之,当我在第二页时,第一个div的数据虽然不可见,但仍然存在。

<ul class="nav nav-pills container-fluid" style = "margin-left:10px;">
  <li class="active"><a href="#homeTab" data-toggle = "pill">Download Data</a></li>
  <li><a href="#metaTab" data-toggle = "pill">Metadata</a></li>
</ul>

<div class="container-fluid tab-content fade in active" id = "homeTab">
 ....    
</div>

<div class="container-fluid tab-content fade" id = "metaTab">
 ....    
</div>

2 个答案:

答案 0 :(得分:1)

您只需要包含bootstrap.js

.tab-pane{
  position:absolute;
  top 200px;
  left:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

<ul class="nav nav-pills container-fluid" style = "margin-left:10px;">
  <li><a href="#homeTab" data-toggle = "pill">Download Data</a></li>
  <li><a href="#metaTab" data-toggle = "pill">Metadata</a></li>
</ul>

<div class="tab-pane fade in active" id = "homeTab">
 ....    FIRST
</div>

<div class="tab-pane fade" id = "metaTab">
 ....    SECOND
</div>

答案 1 :(得分:1)

您滥用标签内容类。它应该包裹在所有标签周围,而标签应该包含标签窗格类,如下所示:

<ul class="nav nav-pills container-fluid" style = "margin-left:10px;">
  <li class="active"><a href="#homeTab" data-toggle = "pill">Download Data</a></li>
  <li><a href="#metaTab" data-toggle = "pill">Metadata</a></li>
</ul>

<div class="tab-content">
    <div role="tabpanel" class="container-fluid tab-pane fade in active" id = "homeTab">
    ...tab 1 content...
    </div>

    <div role="tabpanel" class="container-fluid tab-pane fade" id = "metaTab">
    ...tab 2 content...    
    </div>
</div>

以下是有关bootstrap中的标签的更多信息:http://getbootstrap.com/javascript/#tabs