Make Scrolling NavBar Stick At Top Of Browser In Bootstrap

后端 未结 5 544
野的像风
野的像风 2021-02-04 04:30

I\'m new to Twitter Bootstrap and want to have a NavBar at the bottom of a deep\'ish MastHead and when the user vertically scrolls the page and the NavBar gets to the top of the

相关标签:
5条回答
  • 2021-02-04 05:05

    You can try CSS3 sticky position:

    .sticky {
      position: sticky;
      top: 10px; /* When the element reaches top: 10px, it becomes fixed. */
      z-index: 100;
    }
    

    Browser support: http://caniuse.com/#feat=css-sticky

    0 讨论(0)
  • 2021-02-04 05:06

    The CSS class navbar-fixed-top is what you want to add.

    Here's an example:

    <nav class='navbar navbar-inverse navbar-fixed-top sticky' role='navigation'>
        <!-- nav content -->
    </nav>
    
    0 讨论(0)
  • 2021-02-04 05:14

    In aiming for browser compatibility, the following might be of more use.

    .sticky {
      position: -webkit-sticky;
      position: -moz-sticky;
      position: -ms-sticky;
      position: -o-sticky;
      position: sticky;
      top: 10px;
      z-index: 100;
    }
    
    0 讨论(0)
  • 2021-02-04 05:21

    You'll have to use javascript to do this. Here's a solution that relies on jQuery to convert the navbar positioning to fixed once it gets to the top of the page as well as stick a temporary div in its place to prevent the layout from changing.

    http://jsfiddle.net/T6nZe/

    0 讨论(0)
  • 2021-02-04 05:26

    I believe this is what you are looking for: http://www.w3schools.com/bootstrap/bootstrap_affix.asp

    0 讨论(0)
提交回复
热议问题