如何在Twitter Bootstrap中将导航栏调整到固定宽度?

时间:2012-09-27 06:33:34

标签: css twitter-bootstrap

默认导航栏在浏览器窗口中横向跨越。

<div class="navbar navbar-static-top">

如何声明导航栏仅为750px宽度并放置在中心?
在CSS中设置margin:auto;不起作用。

2 个答案:

答案 0 :(得分:3)

您正在使用的.navbar-static-top强制您的导航栏变为全宽。删除该类,您将获得一个可调整大小的导航栏。然后,您可以将其包装为所需大小的span#

<div class="container">
    <div class="row">
        <div class="span6 offset3">
            <div class="navbar">
                ...
            </div>
        </div>
    </div>
</div>

这里有一个例子:http://jsfiddle.net/simbirsk/xAMYF/

答案 1 :(得分:-1)

使用此选项覆盖Bootstrap的响应式样式,仅对导航栏无响应。

.container .navbar-header,
.container .navbar-collapse {
  margin-right: 0;
  margin-left: 0;
}

/* Always float the navbar header */
.navbar-header {
  float: left;
}

/* Undo the collapsing navbar */
.navbar-collapse {
  display: block !important;
  height: auto !important;
  padding-bottom: 0;
  overflow: visible !important;
}

.navbar-toggle {
  display: none;
}
.navbar-collapse {
  border-top: 0;
}

.navbar-brand {
  margin-left: -15px;
}

/* Always apply the floated nav */
.navbar-nav {
  float: left;
  margin: 0;
}
.navbar-nav > li {
  float: left;
}
.navbar-nav > li > a {
  padding: 15px;
}

/* Redeclare since we override the float above */
.navbar-nav.navbar-right {
  float: right;
}

/* Undo custom dropdowns */
.navbar .navbar-nav .open .dropdown-menu {
  position: absolute;
  float: left;
  background-color: #fff;
  border: 1px solid #ccc;
  border: 1px solid rgba(0, 0, 0, .15);
  border-width: 0 1px 1px;
  border-radius: 0 0 4px 4px;
  -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
          box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
}
.navbar-default .navbar-nav .open .dropdown-menu > li > a {
  color: #333;
}
.navbar .navbar-nav .open .dropdown-menu > li > a:hover,
.navbar .navbar-nav .open .dropdown-menu > li > a:focus,
.navbar .navbar-nav .open .dropdown-menu > .active > a,
.navbar .navbar-nav .open .dropdown-menu > .active > a:hover,
.navbar .navbar-nav .open .dropdown-menu > .active > a:focus {
  color: #fff !important;
  background-color: #428bca !important;
}
.navbar .navbar-nav .open .dropdown-menu > .disabled > a,
.navbar .navbar-nav .open .dropdown-menu > .disabled > a:hover,
.navbar .navbar-nav .open .dropdown-menu > .disabled > a:focus {
  color: #999 !important;
  background-color: transparent !important;
}