问题描述:

How can I keep these tabs in one line while being also responsive for mobiles?

Here is the code.

<div class="navbar">

<div class="navbar-inner">

<ul class="nav nav-tabs">

<li class="active"><a href="#step1" data-toggle="tab">Application</a></li>

<li><a href="#step2" data-toggle="tab">Personal Information</a></li>

<li><a href="#step3" data-toggle="tab">Educational Background</a></li>

<li><a href="#step4" data-toggle="tab">Professional Exam</a></li>

<li><a href="#step5" data-toggle="tab">Work Experiences</a></li>

<li><a href="#step6" data-toggle="tab">References</a></li>

<li><a href="#step7" data-toggle="tab">Family Background</a></li>

</ul>

</div>

</div>

The JSFiddle Here

网友答案:

I think this is what you want. There is no native class to make tabs responsive.

(function($) {

  'use strict';

  $(document).on('show.bs.tab', '.nav-tabs-responsive [data-toggle="tab"]', function(e) {
    var $target = $(e.target);
    var $tabs = $target.closest('.nav-tabs-responsive');
    var $current = $target.closest('li');
    var $parent = $current.closest('li.dropdown');$current = $parent.length > 0 ? $parent : $current;
    var $next = $current.next();
    var $prev = $current.prev();
    var updateDropdownMenu = function($el, position){
      $el.find('.dropdown-menu')
        .removeClass('pull-xs-left pull-xs-center pull-xs-right').addClass( 'pull-xs-' + position );
    };

    $tabs.find('>li').removeClass('next prev');
    $prev.addClass('prev');
    $next.addClass('next');
    
    updateDropdownMenu( $prev, 'left' );
    updateDropdownMenu( $current, 'center' );
    updateDropdownMenu( $next, 'right' );
  });

})(jQuery);
@mixin ellipsis(){
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-wrap: normal;
    width: 100%;
}

@mixin icon-styles(){
  position: relative;
  top: 1px;
  display: inline-block;
  font-family: 'Glyphicons Halflings';
  font-style: normal;
  font-weight: 400;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@mixin transform($transform){
  -webkit-transform: $transform;
  -moz-transform: $transform;
  -ms-transform: $transform;
  -o-transform: $transform;
  transform: $transform;
}

@media screen and (max-width: 479px) {
  .nav-tabs-responsive {
    > li {
      display: none;
      width: 23%;
      > a {
        @include ellipsis();
        width: 100%;
        text-align: center;
        vertical-align: top;
      }
      &.active {
        width: 54%;
        &:first-child {
          margin-left: 23%;
        }
      }
      &.active,
      &.prev,
      &.next {
        display: block;
      }
      &.prev,
      &.next {
        -webkit-transform: scale(0.9);
        transform: scale(0.9);
      }
      &.next > a,
      &.prev > a {
        -webkit-transition: none;
        transition: none;
        .text {
          display: none;
        }
        &:after,
        &:after {
          @include icon-styles();
        }
      }
      &.prev > a:after {
        content: "\e079";
      }
      &.next > a:after {
        content: "\e080";
      }
      &.dropdown {
        > a > .caret {
          display: none;
        }
        > a:after {
          content: "\e114";
        }
        &.active > a {
          &:after {
            display: none;
          }
          > .caret {
            display: inline-block;
          }
        }

        .dropdown-menu {
          &.pull-xs-left {
            left: 0;
            right: auto;
          }
          &.pull-xs-center {
            right: auto;
            left: 50%;
            @include transform(translateX(-50%));
          }
          &.pull-xs-right {
            left: auto;
            right: 0;
          }
        }
      }
    }
  }
}



/**
 * Demo Styles
 */

.wrapper {
  padding: 15px 0;
}

.bs-example-tabs .nav-tabs {
  margin-bottom: 15px;
}

@media (max-width: 479px) {
  #narrow-browser-alert {
    display: none;
  }
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
          <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
           <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
           <style type="text/css">
           
           </style>
           </head>
           <body>
          <div class="bs-example bs-example-tabs" role="tabpanel" data-example-id="togglable-tabs">
      <ul id="myTab" class="nav nav-tabs nav-tabs-responsive" role="tablist">
        <li role="presentation" class="active">
          <a href="#home" id="home-tab" role="tab" data-toggle="tab" aria-controls="home" aria-expanded="true">
            <span class="text">Home</span>
          </a>
        </li>
        <li role="presentation" class="next">
          <a href="#profile" role="tab" id="profile-tab" data-toggle="tab" aria-controls="profile">
            <span class="text">Profile</span>
          </a>
        </li>
        <li role="presentation" class="dropdown">
          <a href="#" id="myTabDrop1" class="dropdown-toggle" data-toggle="dropdown" aria-controls="myTabDrop1-contents">
            <span class="text">Dropdown</span>
            <span class="caret">
            </span>
          </a>
          <ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1" id="myTabDrop1-contents">
            <li>
              <a href="#dropdown1" tabindex="-1" role="tab" id="dropdown1-tab" data-toggle="tab" aria-controls="dropdown1">
                <span>@fat</span>
              </a>
            </li>
            <li>
              <a href="#dropdown2" tabindex="-1" role="tab" id="dropdown2-tab" data-toggle="tab" aria-controls="dropdown2">
                <span>@mdo</span>
              </a>
            </li>
          </ul>
        </li>
        <li role="presentation">
          <a href="#samsa" role="tab" id="samsa-tab" data-toggle="tab" aria-controls="samsa">
            <span class="text">Metamorfoz by Franz Kafka</span>
          </a>
        </li>
      </ul>
      <div id="myTabContent" class="tab-content">
        <div role="tabpanel" class="tab-pane fade in active" id="home" aria-labelledby="home-tab">
          <p>
            Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater
            eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.
          </p>
        </div>
        <div role="tabpanel" class="tab-pane fade" id="profile" aria-labelledby="profile-tab">
          <p>
            Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo
            enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio
            cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
          </p>
        </div>
        <div role="tabpanel" class="tab-pane fade" id="dropdown1" aria-labelledby="dropdown1-tab">
          <p>
            Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy
            hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard
            of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.
          </p>
        </div>
        <div role="tabpanel" class="tab-pane fade" id="dropdown2" aria-labelledby="dropdown2-tab">
          <p>
            Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party locavore wolf cliche high life echo park Austin. Cred
            vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park
            vegan.
          </p>
        </div>
        <div role="tabpanel" class="tab-pane fade" id="samsa" aria-labelledby="samsa-tab">
          <p>
            One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.
          </p>
          <p>
            He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections.
          </p>
          <p>
            The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me?
          </p>
          <p>
            " he thought. It wasn't a dream. His room, a proper human room although a little too small, lay peacefully between its four familiar walls.
          </p>
          <p>
            A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame.
          </p>
          <p>
            It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer. Gregor then turned to look out the window at the dull weather.
          </p>
          <p>
            Drops of rain could be heard hitting the pane, which made him feel quite sad.
          </p>
          <p>
            "How about if I sleep a little bit longer and forget all this nonsense", he thought, but that was something he was unable to do because he was used to sleeping on his right, and in his present state couldn't get into that position. However hard he threw
            himself onto his right, he always rolled back to where he was.
          </p>
          <p>
            He must have tried it a hundred times, shut his eyes so that he wouldn't have to look at the floundering legs, and only stopped when he began to feel a mild, dull pain there that he had never felt before. "Oh, God", he thought, "what a strenuous career
            it is that I've chosen!
          </p>
        </div>
      </div>
    </div>
 
  </body>
  </html>
网友答案:
.nav-tabs{
 display:inline-flex;
}

Hope this helps..

网友答案:

Try to something like this.

.nav-tabs{
  display:inline-flex;
}
.nav-tabs li{
  margin-right: 10px;
  list-style-type:none;
}
<div class="navbar">  <div class="navbar-inner">    <ul class="nav nav-tabs">      <li class="active"><a href="#step1" data-toggle="tab">Application</a></li>      <li><a href="#step2" data-toggle="tab">Personal Information</a></li>      <li><a href="#step3" data-toggle="tab">Educational Background</a></li>      <li><a href="#step4" data-toggle="tab">Professional Exam</a></li>      <li><a href="#step5" data-toggle="tab">Work Experiences</a></li>      <li><a href="#step6" data-toggle="tab">References</a></li>      <li><a href="#step7" data-toggle="tab">Family Background</a></li>    </ul>  </div></div>
网友答案:
@media screen and (min-width: 480px) {
.nav-tabs{
  display:inline-flex;
}
}

Hope this helps

相关阅读:
Top