css - Bootstrap : How to make table inside another table responsive with horizontal scrollbars on mobile devices?

标签 css twitter-bootstrap

我知道 table-responsive 类,但它在这里不起作用并且破坏了 UI。 我的代码如下所示:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<table id="home-table">
  <tr>
    <td class='home-cell'>
      <table class="table table-bordered">
        <caption>Overview</caption>
        <thead>
          <tr>
            <th>Device ID</th>
            <th>Last Reading</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Demo 1</td>
            <td>Reading: R1</td>
          </tr>
        </tbody>
      </table>
    </td>

    <td class='home-cell'>
      <table class="table table-bordered">
        <caption>Alarms and Schedules</caption>
        <thead>
          <tr>
            <th>Device ID</th>
            <th>Details</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Dev 1</td>
            <td>Scheduled 10:00 AM OFF</td>
          </tr>
        </tbody>
      </table>
    </td>
  </tr>
</table>

如何在主表内的两个表中实现单独的响应式水平滚动条?

最佳答案

你可以这样做

<style>
.home-cell.table-responsive {
    width: 150px;
    overflow: auto !important;
    display: inline-block;
}
table .table-bordered {
    width: 190px;
    min-width: 270px;
}
</style>


<table id="home-table">
  <tbody>
    <tr>
      <td class="home-cell table-responsive">
          <table class="table table-bordered">
            <caption>Overview</caption>
              <thead>
                <tr>
                  <th>Device ID</th>
                  <th>Last Reading</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>Demo 1</td>
                  <td>Reading: R1</td>
                </tr>
              </tbody>
            </table>
        </td>

        <td class="home-cell table-responsive">
          <table class="table table-bordered">
            <caption>Alarms and Schedules</caption>
            <thead>
              <tr>
                <th>Device ID</th>
                <th>Details</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>Dev 1</td>
                <td>Scheduled 10:00 AM OFF</td>
              </tr>
            </tbody>
          </table>
        </td>
      </tr>
    </tbody>
</table>

关于css - Bootstrap : How to make table inside another table responsive with horizontal scrollbars on mobile devices?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46955002/

相关文章:

javascript - 如何防止onfocus后自动onmouseover?

jquery - ajax 调用后 Bootstrap 下拉列表不起作用(即使在初始化后)

jquery - 使用 Bootstrap 进行绝对定位

html - h2 在移动设备上强加导航栏崩溃

jquery - 更改切换上的 Bootstrap 按钮文本

html - 最小化 html 表格的样式

css - Bootstrap Images 在另一个之上

javascript - 多个文本区域的字数限制

javascript - 如何将键盘绑定(bind)添加到轮播功能? -jQuery

html - 选择标签在特定屏幕尺寸上获取 "disabled"