我最近想为我的网站使用 Bootstrap 4 获得嵌套(两级)响应式选项卡。请在下面找到,我认为这是一个无需额外 JavaScript 即可管理该问题的干净解决方案:
https://codepen.io/GMaup/pen/eYgJvKd
<div class="card">
<div class="card-header">
<div class="d-flex">
<div class="title pt-3 pb-4">
<h3>Bootstrap 4 - Responsive Nested Tabs without JS (two levels tabs</h3>
</div>
</div>
<!-- START TABS DIV -->
<div class="tabbable-responsive">
<div class="tabbable">
<ul class="nav nav-pills nav-justified" id="linxea-avenir" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="eleve-tab" data-toggle="tab" href="#eleve" role="tab" aria-controls="first" aria-selected="true">Tab 1 with some text</a>
</li>
<li class="nav-item">
<a class="nav-link" id="moyen-tab" data-toggle="tab" href="#moyen" role="tab" aria-controls="second" aria-selected="false">Tab 2 with some text</a>
</li>
<li class="nav-item">
<a class="nav-link" id="faible-tab" data-toggle="tab" href="#faible" role="tab" aria-controls="second" aria-selected="false">Tab 3 with some text</a>
</li>
</ul>
</div>
</div>
<div class="tab-content" style="margin-top:2px">
<div class="tab-pane fade show active" id="eleve" role="tabpanel" aria-labelledby="eleve-tab">
<!-- START TABS DIV -->
<div class="tabbable-responsive">
<div class="tabbable">
<ul class="nav nav-pills nav-justified" id="eleve-nav" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="eleve-eco-tab" data-toggle="tab" href="#eleve-eco" role="tab" aria-controls="first" aria-selected="true">Tab 1.1 with some text</a>
</li>
<li class="nav-item">
<a class="nav-link" id="eleve-standard-tab" data-toggle="tab" href="#eleve-standard" role="tab" aria-controls="second" aria-selected="false">Tab 1.2 with some text</a>
</li>
</ul>
</div>
</div>
<div class="tab-content">
<div class="tab-pane fade show active" id="eleve-eco" role="tabpanel" aria-labelledby="eleve-eco-tab">
<!-- ****************************************************** -->
<!-- START SECTION 1 -->
<p>exemple 1</p>
<p>Resize you screen to see how does it fit</p>
<!-- ****************************************************** -->
<!-- END SECTION 1 -->
</div>
<div class="tab-pane fade" id="eleve-standard" role="tabpanel" aria-labelledby="eleve-standard-tab">
<!-- ****************************************************** -->
<!-- START SECTION 2 -->
<p>exemple 2</p>
<!-- ****************************************************** -->
<!-- END SECTION 2 -->
</div>
</div>
</div>
<div class="tab-pane fade" id="moyen" role="tabpanel" aria-labelledby="moyen-tab">
<div class="tab-content" style="margin-top:2px">
<div class="tab-pane fade show active" id="moyen" role="tabpanel" aria-labelledby="moyen-tab">
<!-- START TABS DIV -->
<div class="tabbable-responsive">
<div class="tabbable">
<ul class="nav nav-pills nav-justified" id="moyen-nav" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="moyen-eco-tab" data-toggle="tab" href="#moyen-eco" role="tab" aria-controls="first" aria-selected="true">Tab 2.1 with some text</a>
</li>
<li class="nav-item">
<a class="nav-link" id="moyen-standard-tab" data-toggle="tab" href="#moyen-standard" role="tab" aria-controls="second" aria-selected="false">Tab 2.2 with some text</a>
</li>
</ul>
</div>
</div>
<div class="tab-content">
<div class="tab-pane fade show active" id="moyen-eco" role="tabpanel" aria-labelledby="moyen-eco-tab">
<!-- ****************************************************** -->
<!-- START SECTION 3 -->
<p>exemple 3</p>
<!-- ****************************************************** -->
<!-- END SECTION 3 -->
</div>
<div class="tab-pane fade" id="moyen-standard" role="tabpanel" aria-labelledby="moyen-standard-tab">
<!-- ****************************************************** -->
<!-- START SECTION 4 -->
<p>exemple 4</p>
<!-- ****************************************************** -->
<!-- END SECTION 4 -->
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="faible" role="tabpanel" aria-labelledby="faible-tab">
<div class="tab-content" style="margin-top:2px">
<div class="tab-pane fade show active" id="faible" role="tabpanel" aria-labelledby="faible-tab">
<!-- START TABS DIV -->
<div class="tabbable-responsive">
<div class="tabbable">
<ul class="nav nav-pills nav-justified" id="faible-nav" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="faible-eco-tab" data-toggle="tab" href="#faible-eco" role="tab" aria-controls="first" aria-selected="true">Tab 3.1 with some text</a>
</li>
<li class="nav-item">
<a class="nav-link" id="faible-standard-tab" data-toggle="tab" href="#faible-standard" role="tab" aria-controls="second" aria-selected="false">Tab 3.2 with some text</a>
</li>
</ul>
</div>
</div>
<div class="tab-content">
<div class="tab-pane fade show active" id="faible-eco" role="tabpanel" aria-labelledby="faible-eco-tab">
<!-- ****************************************************** -->
<!-- START SECTION 5 -->
<p>exemple 5</p>
<!-- ****************************************************** -->
<!-- END SECTION 5 -->
</div>
<div class="tab-pane fade" id="faible-standard" role="tabpanel" aria-labelledby="faible-standard-tab">
<!-- ****************************************************** -->
<!-- START SECTION 6 -->
<p>exemple 6</p>
<!-- ****************************************************** -->
<!-- END SECTION 6 -->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
.nav-pills .nav-link.active, .nav-pills .show>.nav-link {
color: #fff;
background-color: #40bf4f !important;
}
.tabbable .nav-pills {
margin-left: 0px;
}