在navbar中引导4个nav药片

时间:2019-02-28 13:09:40

标签: html bootstrap-4

我是Bootstrap的新手,并且想在导航栏中添加导航栏来切换页面内容(例如标签)。没有导航栏,它可以工作,但是我想将其放在导航栏中。

到目前为止,这是我的代码:

<nav class="navbar navbar-dark bg-dark navbar-expand-sm">
  <span class="navbar-brand mb-0 h1">ioBroker</span>

  <ul class="navbar-nav nav-pills">
    <li class="nav-item active">
      <a class="nav-link active" id="tab-1" data-toggle="tab" role="tab" href="#content-1" aria-selected="true" aria-controls="content-1">Content 1</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" id="tab-2" data-toggle="tab" role="tab" href="#content-2" aria-selected="false" aria-controls="content-2">Content 2</a>
    </li>
  </ul>
</nav>

<main role="main" class="container-full">
  <div class="container-full">
    <div class="tab-content">
      <div class="tab-pane fade show active" id="content-1" aria-labelledby="tab-1" role="tabpanel">Content 1</div>
      <div class="tab-pane fade" id="content-2" aria-labelledby="tab-2" role="tabpanel">Content 2</div>
    </div>
  </div>
</main>

我遇到的问题是,我无法切换回已经打开的“标签”。我删除了“数据切换”属性,该属性适用于按钮,但不适用于内容切换。

1 个答案:

答案 0 :(得分:0)

nav类添加到nav-pills中,内容切换将按预期对Tabs起作用...

<ul class="navbar-nav nav nav-pills">
    <li class="nav-item active">
      <a class="nav-link active" id="tab-1" data-toggle="tab" role="tab" href="#content-1" aria-selected="true" aria-controls="content-1">Content 1</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" id="tab-2" data-toggle="tab" role="tab" href="#content-2" aria-selected="false" aria-controls="content-2">Content 2</a>
    </li>
</ul>

演示:https://www.codeply.com/go/Xr6tLFbqKj