html - 如何防止 Bootstrap 4 表响应溢出它的父级

标签 html css bootstrap-4

我正在尝试使用 Bootstrap 4 table table-responsive 类来让表格显示水平滚动条,这样当表格的宽度较大时它不会溢出它的父容器。

但是,问题是它溢出了它的父容器并且根本不显示滚动条。

table-layout:fixed; 不是解决方案,因为它固定了表格的宽度而不是使其可滚动

body {
  background: #999;
  color: white;
  width: 100%;
}

.parent {
  display: flex;
  background: #333;
  width: 100%;
}

.div-with-table {
  flex: 1 1 auto;
}
<div class="parent">
  <div class="div-with-table">
    <table class="table table-responsive">
      <tr>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
      </tr>
      <tr>
        <td>
          xxxxx
        </td>
        <td>
          xxxxx
        </td>
        <td>
          xxxx
        </td>
        <td>
          xxxx xxxx
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
      </tr>
      <tr>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
        <td>
          x
        </td>
      </tr>
    </table>
  </div>
</div>

https://codepen.io/simPod/pen/PJPBEZ

我做错了什么?

最佳答案

如何添加这条规则:

.parent { overflow-x: scroll; }

关于html - 如何防止 Bootstrap 4 表响应溢出它的父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46268982/

相关文章:

python - 如何删除 Django 模板中的特定 HTML 标记?

javascript - 在 Javascript 字符串中使用 Bootstrap 的 popover 插件

css - 电子邮件通讯渐变颜色无法正确呈现

html - 具有 2px 宽度和背景颜色的空 div 不显示高度为 100%

html - 在小屏幕上居中导航栏品牌

bootstrap-4 - Bootstrap Popover 未显示

php - 如何在 javascript 中创建一个按钮,当用户单击该按钮时将打开 iframe?

html - 在 IE 和 Firefox 中打印预览图像周围的白色边框

javascript - 调整窗口大小时重置 JQuery 函数

css - 带有 bootstrap4 的 Angular 7 粘性页脚