Bootstrap 3: How to attach after 100% height

I'm trying to get my navigator to attach to the top after an introduction set to 100% height, but I'm not sure what is the best way to do this?

The code:

CSS
html, body{ height: 100%; min-height: 100%;} 
.intro {height: 100%;text-align: center;}

HTML
<div class="intro">
  <div class="container">
    <h1>Lorem Ipsum</h1>
  </div>
</div>

<nav>
  <div class="container">
    <div class="navbar-header" data-spy="affix">
      <button type="button" class="navbar-toggle"  data-toggle="collapse" data-target=".navbar-collapse">
        <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="#">Test Navbar</a>
    </div>
    <div 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>

EDIT: I am using Bootstrap 3.0.

+3
source share
2 answers

You can use jQuery function to calculate height #intro

$('nav').affix({
      offset: {
        top: $('.intro').height()
      }
}); 

Here is a demo that works the same way.

http://bootply.com/106399

+4
source

Give your item an navid:

<nav id="derp">
  <div class="container">

and then grab the offset of this element:

$('nav').affix({
      offset: {
        top: $('nav#derp').offset().top
      }
}); 

This is a better approach than relying on previous elements (e.g. height on .intro)

+1
source

All Articles