我正在使用Twitter Bootstrap和您在指南中看到的常规导航栏:http://twitter.github.io/bootstrap/components.html#navbar
我不希望导航向左或向右延伸,而是留在我可以看到两侧的地方,就像在指南中一样。唯一的区别是它将固定在顶部。
我想知道,我如何将它变成一个固定的导航栏,就像我使用navbar-fixed-top
类一样?
答案 0 :(得分:11)
你应该可以这样做:
<div class="navbar-fixed-top container">
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Title</a>
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
</div>
</div>
答案 1 :(得分:3)
Bootstrap 4,在.container
内使用nav
:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<div class="container">
<a class="navbar-brand site-title" href="#">Hello World</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarHelloWorld" aria-controls="navbarHelloWorld" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarHelloWorld">
<ul id="menu-top-menu" class="navbar-nav mr-auto">
<li class="nav-item"><a href="#" class="nav-link">About</a></li>
<li class="nav-item"><a href="#" class="nav-link">Blog</a></li>
<li class="nav-item"><a href="#" class="nav-link">Contact</a></li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" placeholder="Search" type="text">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</div>
</nav>
&#13;
答案 2 :(得分:0)
在 fixed-top
标签前使用 <nav></nav>
。
<div class="fixed-top">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
...more tags...
</nav>
</div>
答案 3 :(得分:-1)
对于Bootstrap 4,它是sticky-top
而不是navbar-fixed-top
。我的代码如下所示:
<nav class="navbar sticky-top navbar-light"> <!-- <<< HERE -->
<a href="/" class="logo1"></a>
<div class="collapse navbar-collapse justify-content-end">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">Product</a>
<a class="nav-item nav-link" href="#">Pricing</a>
<a class="nav-item nav-link" href="#">About</a>
</div>
</div>
</nav>