html - 如何在表格单元格内创建全宽可滚动 div?

标签 html css

如何改变这个:

enter image description here

进入这个:

enter image description here

在这个 fiddle 中: https://jsfiddle.net/d3ckh9qd/2/

table{
  width:100%;
  border-collapse:collapse;
}
td{
  border:1px solid red;
  padding:10px;
}
.td-left{
  width:100%;
}
.div-parent{
  width:800px;
  border:5px solid rgba(0,255,255,0.7);
}
.div-right{
  white-space:nowrap;
  background:rgba(0,0,255,0.1);
}
.pre-scrollable{
  background:rgba(0,255,0,0.3);
  padding:10px;
  white-space:pre;
  overflow:auto;
  width:100%;
  box-sizing:border-box;
}
<div class="div-parent">
  The table below should not exceed parent container:
  <table>
    <tr>
      <td class="td-left">
        <strong>This column should fill the remaining width, respecting the dynamic width of the right column</strong><br>
        <pre class="pre-scrollable">This should match width of the parent container and it's content should scroll horizontally.</pre>
      </td>
      <td class="td-right">
        <strong>This column should autosize to it's contents</strong><br><br>
        <div class="div-right">
          Dynamically generated content goes here
        </div>
        <br>
        <div class="div-right">
          This content has different width each time it loads
        </div>
      </td>
    </tr>
  </table>
</div>

最佳答案

为右侧设置一个固定宽度 px,为左侧设置一个 100% 宽度和一个 overflow-x

关于html - 如何在表格单元格内创建全宽可滚动 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38529221/

相关文章:

html - 堆叠 div——垂直和水平布局的混合

html - IE 6 表行背景颜色?

javascript - 将 HTML 添加到元素的末尾。没有错误;没有添加 HTML

html - 中间框居中变宽,左右浮动直连

html - 在设置为对齐的嵌套 div 中水平居中文本

Angular Material 按钮在对话框打开时处于选择状态

html - 水平对齐表格

javascript - 如果 popstate 事件来自 HTML5 pushstate 的后退或前进操作,我该如何检索?

html - 为什么顶部边距正在崩溃但底部边距却没有?

javascript - 使用 JavaScript 动态加载外部 CSS 文件