bootstrap menu top affix

后端 未结 3 1264
暖寄归人
暖寄归人 2020-12-30 08:16

I\'m trying to do a bootstrap menu with an image and under the menu links, that when it\'s scrolled the menu sticks on the top of the window.

I\'ve found interesting

3条回答
  •  伪装坚强ぢ
    2020-12-30 09:15

    It seems this can be achieved by replacing the CSS you provided by

    #nav {
        width: 100%;
        position:fixed;
    }
    
    #nav.affix {
        top: 0;
    }
    
    #nav > .navbar-inner {
        border-left: 0;
        border-right: 0;
        border-radius: 0;
        -webkit-border-radius: 0;
        -moz-border-radius: 0;
        -o-border-radius: 0;
    }
    

    The main difference is that here, #nav covers both the cases #nav.affix and #nav.affix-top

    See this jsfiddle.

    edit: The problem turns out to occur when #nav's position is inherited. If you fix it, as I suggested, or if you set it to relative, as the other post suggested, your problem will be solved.

提交回复
热议问题