Full width tabs using Bootstrap (Support IE)

后端 未结 8 1301
孤城傲影
孤城傲影 2021-02-02 07:34

I\'m trying to adjust Bootstrap tabs to make them span the full width of their container. Here\'s my code (a minimal working example):


<         


        
相关标签:
8条回答
  • 2021-02-02 08:18

    Maybe I've found your solution:

    Create that class with css:

    .take-all-space-you-can{
        width:100%;
    }
    

    And then apply that class to your li tags into your ul. Doing these all the li takes the space that they can and automatically divide the space in the single row.

    DEMO

    0 讨论(0)
  • 2021-02-02 08:20

    Try

    .nav-tabs > li {
        float:none;
        display: table-cell;
        width: 1%;
    }
    
    0 讨论(0)
  • 2021-02-02 08:20

    Try this solution, just one line of code to achieve that.

    .full-width-tabs > ul > li {   width: 100%;  }  
    

    It will make the tabs to span full width of their container.

    Look at jsfiddle : http://jsfiddle.net/BhGKf/

    0 讨论(0)
  • 2021-02-02 08:25

    You can use javascript and jquery.

    Building on Nick Bull's answer above, you can dynamically determine the number of tabs on the page using Jquery.

    Try this on your html page.

    <script type="text/javascript">
       $(document).ready(function() {
           var numTabs = $('.nav-tabs').find('li').length;
           var tabWidth = 100 / numTabs;
           var tabPercent = tabWidth + "%";
           $('.nav-tabs li').width(tabPercent);
       });
    </script>
    
    0 讨论(0)
  • 2021-02-02 08:33

    Update 2019 - Bootstrap 4

    For future readers, it's now very simple to get full-width Tabs using the nav-fill class. This works on all modern browsers including IE 11+...

    To get full width tabs, use (sized by tab content):

      <ul id="myTabs" class="nav nav-tabs nav-fill">
          <li class="nav-item"><a href="#tab1" data-target="#tab1" data-toggle="tab" class="nav-link">Home</a></li>
          <li class="nav-item"><a href="#tab1" data-target="#tab2" data-toggle="tab" class="nav-link active">Profile</a></li>
          <li class="nav-item"><a href="#tab3" data-target="#tab3" data-toggle="tab" class="nav-link">Messages</a></li>
      </ul>
    

    Demo

    To get full equal width tabs, use nav-justified:

    <ul class="nav nav-tabs nav-justified">
         <li class="nav-item">...</li>
    </ul>
    
    0 讨论(0)
  • 2021-02-02 08:34

    Twitter Bootstrap 3 contains a class for this, the nav-justified class.

    Use it like so:

    <ul class="nav nav-tabs nav-justified">
        <li><a href="#">Foo</a></li>
        <li><a href="#">Bar</a></li>
    </ul>
    
    0 讨论(0)
提交回复
热议问题