我有一个导航栏,在加载时从页面顶部开始大约 200 像素。当我向下滚动时,我希望导航栏将自己“固定”到页面的最顶部,并且在我滚动浏览其余内容时可见。我能够让导航栏保持原位,尽管距离顶部 200 像素,它忽略了我向右拉的内容并将其全部拉向左侧。我需要确保导航栏保持可见并且布局/样式在整个过程中都是相同的。
下面是我的 jsfiddle,它显示了我遇到的问题
<!-- Begin Logo / Search -->
<header class="masthead">
<div class="row">
<div class="span6">
<div class="logo pull-left">
<h1><a href="/">name</a></h1>
</div>
</div>
<div class="span6">
<div class="pull-right hidden-phone">
<form class="search" action="/search" id="site-search">
<input type="hidden" name="records" value="6">
<div class="input-append">
<input type="text" name="q" class="search_box" placeholder="Search" value="" autocomplete="off" />
<button class="btn" type="submit"><i class="icon-search"></i></button>
</div>
</form>
</div>
</div>
</div>
</header>
<!-- Begin Navbar -->
<div>
<div class="navbar navbar-static">
<div class="navbar-inner" id="mastnav">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="nav-collapse collapse">
<ul class="nav"><li><a href="#">nav</a> </li></ul>
<ul class="nav pull-right">
<li>
<a href="/cart"><i class="icon-shopping-cart"></i> <span id="cart-count">1</span></a>
</li>
</ul>
</div>
</div>
</div>
</div><!-- /.navbar -->
</div>