最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin6PV0评论

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
  } 
}
Post a comment

comment list (0)

  1. No comments so far