【问题标题】:How can I get my bootstrap navbar background color to span the entire width of my page?如何让我的引导导航栏背景颜色跨越页面的整个宽度?
【发布时间】:2015-12-12 08:50:04
【问题描述】:

我这里有一个显示导航栏的小提琴。导航栏跨越大部分页面,但不是全部。我希望背景颜色跨越页面的整个宽度(不是链接,只是背景颜色,所以宽度:背景颜色为 100%,但我尝试了 menupartial width 100% 并且它在 css 中不起作用。这里是我的Fiddle

body {
  padding-top: 51px;
  /*padding-bottom: 20px;*/
}
/* Set padding to keep content from hitting the edges */

.front-page-body-content {
  padding-left: 15px;
  padding-right: 15px;
}
/* Override the default bootstrap behavior where horizontal description lists 
   will truncate terms that are too long to fit in the left column 
*/

.dl-horizontal dt {
  white-space: normal;
}
/* Set width on the form input elements since they're 100% wide by default */

input,
select,
textarea {
  max-width: 280px;
}
.navbar-inline {
  display: inline-flex;
}
#navbarSearchQuery {
  float: left;
  margin-top: 8px;
  margin-left: 15px;
  min-width: 280px;
}
@@media only screen and (max-width:768px) {
  #navbarSearchQuery {
    min-width: 240px;
  }
}
#searchQuery {
  /*float: left;*/
  margin-top: 10px;
  /*margin-left: 15px;*/
  min-width: 280px;
}
a.navbar-brand {
  padding-top: 10px;
  padding-bottom: 10px;
}
form#queryWithin {
  max-height: 50px;
}
#ClassDate {
  cursor: default;
}
.menupartial {
  background-color: #16749F;
  opacity: .9;
  width: 100%;
}
.menupartial a {
  color: lightgrey;
  font-weight: bold;
}
.nav-pills > li > a {
  border-radius: 0;
}
.nav-pills > li > a:hover {
  border-radius: 0;
  background-color: #16749F;
  color: white;
}
.nav-pills > li > a:active {
  border-bottom: 5px solid white;
}
<body>
  <div class="container body-content">
    <div class="row menupartial">
      <div class="col-md-12">
        <ul class="nav nav-pills">

          <li><a href="#">Your Schedules</a>
          </li>
          <li><a href="#">Your Messages</a>
          </li>
          <li><a href="#">Your Groups</a>
          </li>
          <li><a href="#">Your Friends</a>
          </li>
        </ul>
      </div>
    </div>
  </Div>
</body>

【问题讨论】:

    标签: html css twitter-bootstrap navbar


    【解决方案1】:

    container 更改为container-fluid 并将menupartial 移动到该div,如下所示:

    <div class="container-fluid menupartial">
    

    container-fluid 是默认的 Bootstrap 类,用于将容器扩展到全角。

    这是一个带有上述类的 jsFiddle:http://jsfiddle.net/AndrewL32/65sf2f66/49/

    【讨论】:

    • 从 Bootstrap 3 开始,fluid 是默认行为,不需要显式的 container-fluid 声明,而不是 &lt;div class="container-fluid menupartial"&gt; &lt;div class="menupartial"&gt; 也可以使用
    【解决方案2】:

    将正文左/右边距设置为0:

    body {
      padding-top: 51px;
      /*padding-bottom: 20px;*/
      margin-left: 0;
      margin-right: 0;
    }
    

    【讨论】:

      【解决方案3】:

      container 更改为container-fluid,然后将menupartial 移动到您的column。您可以从 menupartial 规则中删除 100%。见例子。

      body {
        padding-top: 51px;
        /*padding-bottom: 20px;*/
      }
      /* Set padding to keep content from hitting the edges */
      
      .front-page-body-content {
        padding-left: 15px;
        padding-right: 15px;
      }
      /* Override the default bootstrap behavior where horizontal description lists 
         will truncate terms that are too long to fit in the left column 
      */
      
      .dl-horizontal dt {
        white-space: normal;
      }
      /* Set width on the form input elements since they're 100% wide by default */
      
      input,
      select,
      textarea {
        max-width: 280px;
      }
      .navbar-inline {
        display: inline-flex;
      }
      #navbarSearchQuery {
        float: left;
        margin-top: 8px;
        margin-left: 15px;
        min-width: 280px;
      }
      @media only screen and (max-width: 768px) {
        #navbarSearchQuery {
          min-width: 240px;
        }
      }
      #searchQuery {
        /*float: left;*/
        margin-top: 10px;
        /*margin-left: 15px;*/
        min-width: 280px;
      }
      a.navbar-brand {
        padding-top: 10px;
        padding-bottom: 10px;
      }
      form#queryWithin {
        max-height: 50px;
      }
      #ClassDate {
        cursor: default;
      }
      .body-content .menupartial {
        background-color: #16749F;
        opacity: 0.9;
      }
      .body-content .menupartial a {
        color: lightgrey;
        font-weight: bold;
      }
      .nav.nav-pills > li > a {
        border-radius: 0;
      }
      .nav.nav-pills > li > a:hover {
        border-radius: 0;
        background-color: #16749F;
        color: white;
      }
      .nav.nav-pills > li > a:active {
        border-bottom: 5px solid white;
      }
      <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
      
      <body>
        <div class="container-fluid body-content">
          <div class="row">
            <div class="col-md-12 menupartial">
              <ul class="nav nav-pills">
                <li><a href="#">Your Schedules</a>
      
                </li>
                <li><a href="#">Your Messages</a>
      
                </li>
                <li><a href="#">Your Groups</a>
      
                </li>
                <li><a href="#">Your Friends</a>
      
                </li>
              </ul>
            </div>
          </div>
        </Div>
      </body>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-12
        • 2019-02-15
        • 1970-01-01
        • 2019-04-06
        相关资源
        最近更新 更多