Responsive table handling in Twitter Bootstrap

后端 未结 4 641
你的背包
你的背包 2020-12-02 09:36

When a table\'s width exceed the span\'s width, like this page: http://jsfiddle.net/rcHdC/

You will see the table\'s content is outside of the span.

相关标签:
4条回答
  • 2020-12-02 10:02

    One option that is available is fooTable. Works great on a Responsive website and allows you to set multiple breakpoints... fooTable Link

    0 讨论(0)
  • 2020-12-02 10:16

    If you are using Bootstrap 3 and Less you could apply the responsive tables to all resolutions by updatingthe file:

    tables.less
    

    or overwriting this part:

    @media (max-width: @screen-xs) {
      .table-responsive {
        width: 100%;
        margin-bottom: 15px;
        overflow-y: hidden;
        overflow-x: scroll;
        border: 1px solid @table-border-color;
    
        // Tighten up spacing and give a background color
        > .table {
          margin-bottom: 0;
          background-color: #fff;
    
          // Ensure the content doesn't wrap
          > thead,
          > tbody,
          > tfoot {
            > tr {
              > th,
              > td {
                white-space: nowrap;
              }
            }
          }
        }
    
        // Special overrides for the bordered tables
        > .table-bordered {
          border: 0;
    
          // Nuke the appropriate borders so that the parent can handle them
          > thead,
          > tbody,
          > tfoot {
            > tr {
              > th:first-child,
              > td:first-child {
                border-left: 0;
              }
              > th:last-child,
              > td:last-child {
                border-right: 0;
              }
            }
            > tr:last-child {
              > th,
              > td {
                border-bottom: 0;
              }
            }
          }
        }
      }
    }
    

    With:

    @media (max-width: @screen-lg) {
      .table-responsive {
        width: 100%;
    ...
    

    Note how I changed the first line @screen-XX value.

    I know making all tables responsive may not sound that good, but I found it extremely useful to have this enabled up to LG on large tables (lots of columns).

    Hope it helps someone.

    0 讨论(0)
  • 2020-12-02 10:19

    There are many different things you can do when dealing with responsive tables.

    I personally like this approach by Chris Coyier:

    • http://css-tricks.com/responsive-data-tables/

    You can find many other alternatives here:

    • http://css-tricks.com/responsive-data-table-roundup/
    • http://bradfrost.github.io/this-is-responsive/patterns.html#tables

    If you can leverage Bootstrap and get something quickly, you can simply use the class names ".hidden-phone" and ".hidden-tablet" to hide some rows but this approach might to be the best in many cases. More info (see "Responsive utility classes"):

    • http://twitter.github.io/bootstrap/scaffolding.html#responsive
    0 讨论(0)
  • 2020-12-02 10:23

    Bootstrap 3 now has Responsive tables out of the box. Hooray! :)

    You can check it here: https://getbootstrap.com/docs/3.3/css/#tables-responsive

    Add a <div class="table-responsive"> surrounding your table and you should be good to go:

    <div class="table-responsive">
      <table class="table">
        ...
      </table>
    </div>
    

    To make it work on all layouts you can do this:

    .table-responsive
    {
        overflow-x: auto;
    }
    
    0 讨论(0)
提交回复
热议问题