5

我正在使用 Twitter Bootstrap 和您在指南中看到的常规导航栏:http: //twitter.github.io/bootstrap/components.html#navbar

我不希望导航一直向左或向右伸展,而是保持在我可以看到两侧的位置,就像在指南中一样。唯一的区别是它会固定在顶部。

我想知道,如何使它成为一个固定的导航栏,就好像我在使用navbar-fixed-top类一样?

4

4 回答 4

13

你应该能够做到:

<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>
于 2013-06-25T22:19:27.360 回答
4

Bootstrap 4, use .container inside nav:

Demo

<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>

于 2017-11-11T00:03:17.550 回答
0

在标签fixed-top之前使用。<nav></nav>

<div class="fixed-top">
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        ...more tags...
    </nav>
</div>
于 2021-07-04T23:12:30.383 回答
0

对于 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>
于 2017-06-25T21:03:32.747 回答