css - 带有 Bootstrap 的父导航栏内的全宽辅助导航栏

标签 css twitter-bootstrap-3

我正在尝试使用 Bootstrap 创建一个非常简单的双导航栏效果。我现在遇到的唯一问题是第二个/底部导航栏没有延伸到整个浏览器宽度。这是我的代码...

<nav class="navbar navbar-fixed-top navbar-inverse">
      <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" style = "line-height: 30px;">
            <span class="sr-only">Toggle navigation</span>
            <span class="glyphicon glyphicon-menu-hamburger" style="color:#fff;"></span>
          </button>
         <a class="navbar-brand" href="#" style = "line-height: 30px;">brand</a> 

        </div>
        <div id="navbar" class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <!-- <li><a href="#contact">Button</a></li> -->
          </ul>
        </div><!-- /.nav-collapse -->

        <!-- this is the second navbar element that never takes up the full width available-->
        <div class="nav navbar-default" style="background-color: #66CCFF;">
                <ul class="nav navbar-nav">
                    <li><a href="#" class="glyphicon glyphicon-search"></a></li>
                    <li class="divider-vertical"></li>
                    <li><a href="#" class="glyphicon glyphicon-cloud"></a></li>
                    <li class="divider-vertical"></li>
                    <li><a href="#" class="glyphicon glyphicon-th"></a></li>
                </ul>
            </div>
      </div><!-- /.container -->
    </nav><!-- /.navbar -->

我玩过各种不同的导航栏类型和 css 样式(例如宽度:100%),但我似乎无法弄清楚如何使第二个导航栏(即包含 3 个字形图标的导航栏)具有相同的宽度作为其 parent 。

非常感谢任何关于我可能做错的想法!

最佳答案

您需要使用 container-fluid 而不是 container 因为后者具有固定宽度。

.container-fluid 仍然包含用于填充的 CSS 规则。您可以尝试使用自定义类覆盖它。

.container-fluid.no-padding {
  padding: 0;
}
.no-padding .navbar-header {
  padding-left: 10px; /* Align the Brand text */
}
@media (max-width: 768px) {
  .no-padding .navbar-nav {
    padding-left: 10px; /* Align the icons on small screens */
  }
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet" />
<nav class="navbar navbar-fixed-top navbar-inverse">
  <div class="container-fluid no-padding">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar" style="line-height: 30px;">
        <span class="sr-only">Toggle navigation</span>
        <span class="glyphicon glyphicon-menu-hamburger" style="color:#fff;"></span>
      </button>
      <a class="navbar-brand" href="#" style="line-height: 30px;">brand</a> 

    </div>
    <div id="navbar" class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <!-- <li><a href="#contact">Button</a></li> -->
      </ul>
    </div>
    <!-- /.nav-collapse -->

    <!-- this is the second navbar element that never takes up the full width available-->
    <div class="nav navbar-default" style="background-color: #66CCFF;">
      <ul class="nav navbar-nav">
        <li>
          <a href="#" class="glyphicon glyphicon-search"></a>
        </li>
        <li class="divider-vertical"></li>
        <li>
          <a href="#" class="glyphicon glyphicon-cloud"></a>
        </li>
        <li class="divider-vertical"></li>
        <li>
          <a href="#" class="glyphicon glyphicon-th"></a>
        </li>
      </ul>
    </div>
  </div>
  <!-- /.container -->
</nav>
<!-- /.navbar -->

关于css - 带有 Bootstrap 的父导航栏内的全宽辅助导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32699818/

相关文章:

css - Bootstrap 3 - 禁用导航栏折叠

html - bootstrap - 使用完整的容器空间将多个按钮与大文本框对齐

jquery - 与 Bootstrap 菜单不一致的问题

html - 位置 :relative set on editable dropdown is displaying over header of web page when scroll down

css - 从数据内容更改字体

animation - 变换 : rotate. 上的 CSS3 动画获取旋转元素当前度数的方法?

html - 将文本放在底部右对齐的 div 容器中

javascript - 响应式幻灯片导航按钮

css - 对齐社交媒体图标并将它们放置在页面中央

jquery - 如何使用引导 Accordion 折叠两个 Accordion