html - 如果我的表格有很多内容不适合我的屏幕,如何使我的表格可滚动/响应?

标签 html css twitter-bootstrap twitter-bootstrap-3 responsive

我在我的面板中添加了一个 overflow-x:scroll,因为我的表中有很多列,滚动效果很好。但是面板标题的蓝色停在页面的右侧;在那之后面板标题的右边是白色的,看起来很糟糕。如何使蓝色面板标题向右拉伸(stretch),使其不会在页面右侧截断?

<div class="panel panel-primary" style="overflow-x:scroll">
    <div class="panel-heading">Heading</div>
        <table class="table table-striped">
            <tr>
                <th></th>
            </tr>
            <tr>
                <td></td>
            </tr>
        </table>
    </div>
</div>

最佳答案

  1. 不要像使用 overflow-x: scroll 那样添加内联样式;
  2. 您的问题的解决方案是在您的表格周围添加一个 .table-responsive div。

来自bootstrap documentation :

Create responsive tables by wrapping any .table in .table-responsive to make them scroll horizontally on small devices (under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="panel panel-primary">
  <div class="panel-heading">Heading</div>
  <div class="table-responsive">
    <table class="table">
      <thead>
        <tr>
          <th>#</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">1</th>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
        </tr>
        <tr>
          <th scope="row">2</th>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
        </tr>
        <tr>
          <th scope="row">3</th>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

无论您有多少行/列,您都可以通过这种方式获得一个可以很好滚动的表格。

关于html - 如果我的表格有很多内容不适合我的屏幕,如何使我的表格可滚动/响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40104363/

相关文章:

javascript - 如果 URL 是(值),则使用 css 类

javascript - 循环链表未按预期工作(jquery)

css - 如何在 Bootstrap 表中为复选框列添加标题

css - 为 Bootstrap 列表组元素制作页眉/页脚的好方法是什么?

javascript - Bootstrap table toggle ...如果打开一个新的切换,如何关闭以前的切换?

html - 如何在 iframe 中添加停止按钮?

css - 看过一次后如何使视频模糊?

css - 为什么悬停 div 元素在 iOS Safari (iPhone/iPad) 上不起作用?

html - 屏幕外绝对定位 Div 导致水平滚动

javascript - 在 <li> <span> 列表中多次显示无