最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I keep nav-tabs in boostrap fixed on the top while scrolling? - Stack Overflow

programmeradmin0浏览0评论

I have a Page in Rails which has 4-5 tabs. Each tab renders a partial (say a page). I want to be able to keep the tabs fixed on the screen at the top or some margin from the top, even though a user scrolls down. I have used Bootstrap's <ul class="nav nav-tabs"> for tabs.

I have a Page in Rails which has 4-5 tabs. Each tab renders a partial (say a page). I want to be able to keep the tabs fixed on the screen at the top or some margin from the top, even though a user scrolls down. I have used Bootstrap's <ul class="nav nav-tabs"> for tabs.

Share Improve this question asked May 4, 2017 at 13:02 the railslearnerthe railslearner 1011 gold badge1 silver badge10 bronze badges 2
  • stackoverflow./questions/23020763/… – mxr7350 Commented May 4, 2017 at 13:04
  • I have already read it, and tried. The scrolling content overlaps the tabs. – the railslearner Commented May 4, 2017 at 13:06
Add a ment  | 

2 Answers 2

Reset to default 2

Add class navbar-fixed-top to nav ul

@media
only screen and (your condition)
{
 [class*="nav-tabs"] 
  {
    position: fixed;
    z-index: 9;
    background-color: #fff;
    margin-top: -11%; // adjust according to your need
  }
  // you are probably gonna mess up tab-content margin as well, so adjust it as I have shown below
  [class*="tab-content"] 
  {
    margin-top: 5%; // insert n% as per your need
  } 
}
发布评论

评论列表(0)

  1. 暂无评论