在navbar-fixed-top之前添加标题图像

时间:2013-02-27 05:42:39

标签: twitter-bootstrap

如何添加标题图片,使其显示在导航栏固定顶部的顶部。当用户向下滚动时,导航栏会粘在顶部?

我已尝试将其添加到容器中,但它无法按预期工作。

到目前为止,这是我的代码。

<body>
 <header>
  <img src="header/1024x100.png">
 </header>
 <div class="container-fluid">
  <div class="navbar navbar-inverse navbar-fixed-top">
   <div class="navbar-inner">
    <div class="container-fluid">
      <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>
      <a class="brand" href="#"></a>
      <div class="nav-collapse collapse">
        <p class="navbar-text pull-right">
          Logged in as <a href="#" class="navbar-link">Username</a>
        </p>
        <ul class="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>
  </div>
</div>

感谢。

1 个答案:

答案 0 :(得分:3)

JsFiddle with scrolling nav check link

注意:如果您的图片小于屏幕尺寸,请将此代码段插入您的css

.masthead img{
width:100%;
 }

html应如下所示:

<div class="masthead">
<img src="http://placehold.it/940x150"/>
</div>
<!-- /container -->
<div class="navbar affix-top" data-spy="affix" data-offset-top="150">
<div class="navbar-inner">
    <div class="container">
               <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>
 <!-- navbar -->
<div class="container">
  <div class="row-fluid">
    <div class="span4">
    content goes here 
    </div>
   </div>
 </div>