简体   繁体   English

Sticky-top 不适用于 bootstrap 导航栏

[英]Sticky-top not working with bootstrap navbar

I can't seem to figure out why the sticky-top function is not working.我似乎无法弄清楚为什么粘顶功能不起作用。 I got around the issue by writing some horrid looking javascript code but was hoping someone might have an idea.我通过编写一些看起来很糟糕的 javascript 代码来解决这个问题,但希望有人可能有想法。 I just want it to stick to the top of the screen as I scroll over some other element on the page at 50px.我只是希望它在我以 50 像素滚动页面上的其他元素时粘在屏幕顶部。

The navbar looks and works as intended (as shown in the picture) but this might be a PEBCAK situation...导航栏的外观和工作方式符合预期(如图所示),但这可能是 PEBCAK 情况...

 <body data-spy="scroll" data-target=".navbar" data-offset="50"> <nav class="navbar navbar-default navbar-fixed-top" id="secondNav"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Portfolio</a> </div> <div> <div class="collapse navbar-collapse" id="myNavbar"> <ul class="nav navbar-nav navbar-right"> <li><a href="#section1">Section 1</a></li> <li><a href="#section2">Section 2</a></li> <li><a href="#section3">Section 3</a></li> <li><a href="#section4">Section 4</a></li> </ul> </div> </div> </div> </nav>

Instead of using navbar-fixed-top try just fixed-top .不要使用navbar-fixed-top尝试只使用fixed-top Let me know if this helps.如果这有帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM