Bootstrap中的默认固定顶部导航栏跨越视口的整个宽度。我希望它显示在容器div
中包含它。我可以使用以下CSS覆盖来包含左侧:
.navbar-fixed-top,
.navbar-fixed-bottom {
position: fixed;
width:100%;
right: auto;
left: auto;
z-index: 1030;
}
但导航栏仍然延伸到右侧的完整窗口。
答案 0 :(得分:0)
确保所有内容都嵌套在bootstrap中
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<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="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-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>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="starter-template">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>
</div><!-- /.container -->
答案 1 :(得分:0)
只需从您自己的样式表中的navbar元素中取出颜色,然后将所需的颜色添加到导航栏中的内部容器中。
.navbar {
background-color: transparent;
background: transparent;
border:none;
}
.navbar .container {
background-color: black;
background: blue;
border:grey;
}