如何使用 bootstrap 创建类似响应式标签的导航栏?

how to create navbar like responsive tab using bootstrap?

如何使用 bootstrap 创建类似响应式标签的导航栏? 我的要求是制作像 bootstrap 导航栏一样响应迅速的选项卡。 我试过这样...

<nav class="navbar navbar-default">
      <!-- We use the fluid option here to avoid overriding the fixed width of a normal container within the narrow content columns. -->
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-6">
            <span class="sr-only">Toggle</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>

        </div>

        <div class="navbar-collapse in" id="bs-example-navbar-collapse-6" style="height: auto;">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
            <li><a href="#">Link</a></li>
          </ul>
        </div><!-- /.navbar-collapse -->
      </div>
    </nav>

谁能帮忙....

Bootstrap 使用媒体查询根据屏幕宽度更改 header,因此您也需要使用它们。

当宽度大于 768px 时,列表项会显示,低于该宽度的任何内容都会导致它们被隐藏。

HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <header>
    <div class="navbar-header">
      <a class="navbar-brand">Bootstrap</a>
      <div class="navbar-toggle"></div>
    </div>
    <nav class="navbar navbar-default">
    <ul>
      <li>About</li>
      <li>Services</li>
      <li>Contact</li>
      <li>Location</li>
    </ul>   
  </nav>
  </header>
</body>
</html>

CSS

@media (min-width: 768px) {
  .navbar li {
    float: left;
    list-style-type: none;
    display: block;
    padding: 15px 10px;
  }
  .navbar-toggle {
    display: none;
  }
  .navbar {
    display: block !important;
  }
}

.navbar-brand {
  display: block;
  float: left;
  background: #6f5499;
  padding: 15px;
}

.navbar-toggle {
  position: relative;
  float: right;
  background-color: #6f5499;
  padding: 20px;
}
.navbar {
  display: none;
}

参见this jsbin

试试这个:

<nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Bootstrap theme</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
              <ul class="dropdown-menu" role="menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Nav header</li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

这里是一个示例 jsfiddle 如何在 bootstrap 中创建响应式菜单。

我找到了一个有用的插件来做到这一点 try this responsive tabs

选项卡在到达 CSS 断点时转换为手风琴。您可以使用此插件作为在桌面、平板电脑和移动设备上优雅地显示选项卡的解决方案。