33

I have seen this post, but being a new user I can't comment to ask for clarification.

I'm using the justified nav tabs in Bootstrap and don't want them to stack on small screens, since I only have 2 tabs. I would like them to remain side by side, just shrink down to fit the screen. This is what I have:

    <!-- Nav tabs -->
<ul class="nav nav-tabs nav-justified" id="myTab">
  <li class="active"><a href="#ratings" data-toggle="tab">Ratings</a></li>
  <li><a href="#reviews" data-toggle="tab">Reviews</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane active" id="ratings">This is a rating section</div>
  <div class="tab-pane" id="reviews">This is for reviews. There should be some styling here.</div>
</div>

As the related post suggests using media queries, I cannot seem to make that work. I had tried setting the following to target just small screens:

    @media (max-width: 768px) {
  .nav-justified > li {display: table-cell;}
}

I'm not sure what I'm doing wrong so any help is greatly appreciated.

Community
  • 1
  • 1
user2654108
  • 365
  • 1
  • 4
  • 6
  • Seems correct to me and working here (note I added more styles to make tabs look correct) http://jsbin.com/wakuf/1/edit. Are you sure your CSS is being called? – davidpauljunior Feb 26 '14 at 05:15
  • Thanks, it worked! The only difference was that I didn't have the 1% width applied originally, and that seems to have made it work. – user2654108 Feb 26 '14 at 22:26
  • This doesn't always work for more than two tabs. I tried with 3 nav-pills and it left too much space between them, kicking the third to the next line. The accepted answer did work, though (using col-xs-4). – Rachel S Feb 10 '16 at 18:36

9 Answers9

52

The problem with some of the other solutions is that the tabs will lose their borders and other design elements. The following media queries more fully ensure the tabs match in both condensed and wider displays:

@media (max-width: 768px) {
  .nav-justified > li {
    display: table-cell;
    width: 1%;
  }
  .nav-justified > li > a  {
    border-bottom: 1px solid #ddd !important;
    border-radius: 4px 4px 0 0 !important;
    margin-bottom: 0 !important;
  }
}
peter bray
  • 1,325
  • 1
  • 12
  • 22
  • 2
    The only solution the seemed to work for me. Best answer by far! Thanks – Suleiman19 Jun 20 '15 at 10:51
  • This seems a nice solution, but has one drawback: If you have many
  • items, you lose the responsiveness and get ugly horizontal scrollbar below certain width. Does anyone know how to fix this?
  • – mzrnsh Sep 02 '15 at 08:19
  • I improved it adding this other rule at the end in the media query: .nav-justified > li.active > a { border-bottom-width: 0px !important; } – Gianluigi Liguori May 04 '18 at 20:17
  • Much better solution. I wish the masses could vote this as the accepted answer. – Wonko the Sane Nov 28 '20 at 15:04