是否有一种方法可以将水平滚动条添加到HTML表中?我实际上需要它是可滚动的,垂直和水平取决于表如何增长,但我不能得到任何滚动条出现。


当前回答

不管怎样,我找到的最好答案是: https://github.com/filamentgroup/tablesaw/issues/58#issuecomment-63966574

table.tablesaw
{
    table-layout: fixed;
    max-width: none;
    width: auto;
    min-width: 100%;
}

其他回答

用下面的样式将表格包装成DIV:

div.wrapper {
  width: 500px;
  height: 500px;
  overflow: auto;
}

为此使用CSS属性“overflow”。

简短的总结:

overflow: visible|hidden|scroll|auto|initial|inherit;

e.g.

table {
    overflow: scroll;
}

首先,做一个显示:块你的表

然后,将overflow-x:设置为auto。

table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}

又好又干净。没有多余的格式。

这里有更多涉及的例子,从我的网站上的一个页面滚动表标题。

如果一个关于单元格没有填充整个表的问题,附加以下额外的CSS代码:

table tbody {
    display: table;
    width: 100%;
}
.wrapper {
  width: 0;
  min-width: 100%; //width 0, but min-width 100?? yes, I know...
  overflow: auto;
}
<div class="wrapper">
  <table></table>
</div>

表可以有任何宽度。我通常使用100%或max-content作为表。

不管怎样,我找到的最好答案是: https://github.com/filamentgroup/tablesaw/issues/58#issuecomment-63966574

table.tablesaw
{
    table-layout: fixed;
    max-width: none;
    width: auto;
    min-width: 100%;
}