使用响应式表bootstrap3保持列宽

Thi*_*dio 3 html css twitter-bootstrap twitter-bootstrap-3

我有一个7列(td)的表.我正在设置一个固定的宽度,它可以在桌面上使用浏览器完美地工作.但是,当我调整浏览器大小以模拟移动电话甚至通过移动设备访问此页面时,它将不会考虑列宽.

我不会把整个HTML,但它基本上是:

<div class="table-responsive">
    <table>
         <tr>
              <td class="w-large">Column 1</td>
              <td class="w-medium">Column 2</td>
              <td class="w-medium">Column 3</td>
              <td class="w-medium">Column 4</td>
              <td class="w-medium">Column 5</td>
              <td class="w-medium">Column 6</td>
              <td class="w-medium">Column 7</td>
         </tr>
    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.w-large {
    width: 198px;
}

.w-medium {
    width: 176px;
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在移动设备上保持列宽?bootstrap是否有一个特殊的类来执行此类响应表响应?

Chr*_*ina 9

.table-responsive应该就像你拥有它一样,在桌子周围的包装器上.宽度不会保留,因为类会放置 white-space: nowrap;th,td等.请执行以下操作:

@media screen and (max-width: 767px) {
  .alt-table-responsive {
    width: 100%;
    margin-bottom: 15px;
    overflow-y: hidden;
    overflow-x: auto;
    -ms-overflow-style: -ms-autohiding-scrollbar;
    border: 1px solid #dddddd;
    -webkit-overflow-scrolling: touch;
  }
}
Run Code Online (Sandbox Code Playgroud)

HTML

<div class="alt-table-responsive">
Run Code Online (Sandbox Code Playgroud)