Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

css - Bootstrap affix issues with sticky top navigation

So I am having issues when trying to implement the affix sidebar with a sticky top nav, when scrolling on the page or clicking on the affix sidebar, the content header is off by 40 pixel (getting covered by the sticky top nav)

Basically the content is not showing appropriately under the fixed navigation.

Any idea here how to fix it will be much appreciated!

Live site example here

http://www.melindayang.com/portfolio-carmax.html

Cold below:

The sticky top-nav

   <div class="collapse navbar-collapse navbar-ex1-collapse">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="aboutme.html">About Me</a>
                </li>
                <li><a href="document/MYang Resume.pdf"target="_blank">Résumé</a>
                </li>
                <li><a href="http://melindamcdm.wordpress.com/" target="_blank">Blog</a>
                </li>
                </ul> 
        </div>

The affix sidebar

<div class="col-xs-3" id="myScrollspy">
            <ul class="nav nav-tabs nav-stacked" data-spy="affix" data-offset-top="125" id="myNav">
                <li class="active">
                    <a href="#section-1">Summary</a></li>
                <li><a href="#section-2">Research</a></li>
                <li><a href="#section-3">Ideation</a></li>
                <li><a href="#section-4">Prototype</a></li>
                <li><a href="#section-5">Results</a></li>
        </ul>
    </div>

The Content

 <div class="col-xs-9">
        <div id="section-1">
 <p> 12345, Content goes here</p>
</div>
  <div id="section-2">
 <p> 12345, Content goes here</p>
</div>
  <div id="section-3">
 <p> 12345, Content goes here</p>
</div>
  <div id="section-4">
 <p> 12345, Content goes here</p>
</div>
  <div id="section-5">
 <p> 12345, Content goes here</p>
</div>
</div>

The JS

<script type="text/javascript">
$(document).ready(function(){
$("#myNav").affix({
    offset: { 
        top: 190 
    }
    });
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add padding to the body

body
{
    padding: 70px 0 0 0;
}

Bootstrap nav is 50px high, plus whatever margin you want between content and nav.

Edit: Check here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...