是否有一种方法可以将水平滚动条添加到HTML表中?我实际上需要它是可滚动的,垂直和水平取决于表如何增长,但我不能得到任何滚动条出现。
当前回答
桌子上“超过100%的宽度”真的很适合我。
.table-wrap { 宽度:100%; 溢出:汽车; } 表{ 表布局:固定; 宽度:200%; }
其他回答
你试过CSS溢出属性了吗?
overflow: scroll; /* Scrollbar are always visible */
overflow: auto; /* Scrollbar is displayed as it's needed */
更新 正如其他用户指出的那样,仅仅添加滚动条是不够的。 所以,请参阅下面的评论和回答并投票。
将表格插入到div中,这样表格就会有完整的长度
HTML
<div class="scroll">
<table> </table>
</div>
CSS
.scroll{
overflow-x: auto;
white-space: nowrap;
}
用下面的样式将表格包装成DIV:
div.wrapper {
width: 500px;
height: 500px;
overflow: auto;
}
为此使用CSS属性“overflow”。
简短的总结:
overflow: visible|hidden|scroll|auto|initial|inherit;
e.g.
table {
overflow: scroll;
}
这对我来说很管用
.wrapper {
overflow-x: auto;
white-space: nowrap;
}
.wrapper table {
width: auto;
min-width: 100%;
}
<div class="wrapper">
<table>...</table>
</div>