Responsive table handling in Twitter Bootstrap

后端 未结 4 673
你的背包
你的背包 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: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.

提交回复
热议问题