Html 如何将水平滚动条添加到 div 中的表格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10925019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I add a horizontal scrollbar to a table in a div?
提问by Sandy
How can I add a horizontal scroll bar to a table that is inside a div? Is there CSS solution for this?
如何向 div 内的表格添加水平滚动条?有没有针对此的 CSS 解决方案?
回答by Victoria Ruiz
You will not be able to add a scrollbar to a table, but you can add it to a DIV containing your table.
您将无法向表格添加滚动条,但可以将其添加到包含您的表格的 DIV。
For example:
例如:
<div style="width: 400px; height: 200px; overflow: scroll;">
<table>...</table>
</div>
回答by DRTauli
If you only want a horizontal scrollbar use overflow-x:auto; then set the width.
如果您只想要一个水平滚动条,请使用 overflow-x:auto; 然后设置宽度。
div
{
width: 300px;
overflow-x:auto;
overflow-y:hidden;
}
回答by Tooraj Jam
Try it:
尝试一下:
div {
display: block;
height: 200px;
overflow: scroll;
}
回答by jasssonpet
To add the scrollbar use overflow:
要添加滚动条使用溢出:
div {
width: 100px;
overflow: auto;
}
You have to add width to the table too:
您还必须为表格添加宽度:
table {
width: 300px;
}