使用 html 的表格的垂直滚动条
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2897967/
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
vertical scrolling bar for a table using html
提问by kawtousse
I want to fixe a height for my html table in the web page and if it pass the height automatically a vertical scrolling bar is shown.
我想在网页中为我的 html 表固定一个高度,如果它自动传递高度,则会显示一个垂直滚动条。
please help.
请帮忙。
回答by Robert Greiner
It's not the table that scrolls, it is the div behind it.
滚动的不是表格,而是它背后的 div。
<div style="height:200px; overflow-y: scroll;">
<table>
....
</table>
</div>
use overflow-y
if you only want a vertical scroll bar and overflow
if you want both a vertical and horizontal.
使用overflow-y
,如果你只想要一个垂直滚动条和overflow
如果要同时使用垂直和水平。
Note:setting an overflow attribute to scroll will always display the scrollbars. If you want the horizontal/vertical scrollbars to only show up when needed, use auto
.
注意:将溢出属性设置为滚动将始终显示滚动条。如果您希望水平/垂直滚动条仅在需要时显示,请使用auto
.
回答by Tejs
You'd want to place the table inside of a div like so:
你想把表格放在一个 div 里面,如下所示:
<div style="height: 400px; overflow: auto;">
<!-- Html Elements --!>
</div>
Anything inside that div, when it goes over 400px in height, will overflow and a scrollbar will be shown.
该 div 中的任何内容,当它的高度超过 400 像素时,都会溢出并显示滚动条。