Bootstrap Affix Nav Causes Div Below To Jump Up

前端 未结 2 1459
梦毁少年i
梦毁少年i 2021-01-31 18:05

I\'ve created a JSFiddle using Bootstrap\'s affix function to make a nav stay at the top of the screen once you scroll down and the header moves out of view.

The problem

相关标签:
2条回答
  • 2021-01-31 18:47

    This seems to work:

    .nav-wrapper
    {
        min-height:50px;
    }
    

    Updated jsFiddle: http://jsfiddle.net/yYE62/5/

    What's happening is that the affix plugin makes the element with the .affix class have a fixed position in the document. This removes the affixed element from the flow (or layout, if you prefer) and causes the container to collapse. When that happens, the content below slides up to fill the space that the affixed element used to occupy.

    By adding the rule above, you tell that container to maintain a minimum height regardless of whether it has content or not. It doesn't have to be 50px; that's the default height of .navbar, so adjust to match your needs. If you don't want all .nav-wrappers to have a minimum height, assign an id and use that instead.

    0 讨论(0)
  • 2021-01-31 18:57

    You need an extra wrapper for that to work flawlessly. Give it a minimum-height exactly same as the one you're affix`in :)

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