本文的方法是使用 width 属性创建 100% 宽度的表格,并使用 overflow-y 属性在表格体内创建垂直滚动。溢出属性用于在表中创建滚动条。使用显示:块;属性来显示块级元素。既然更改了 tbody 的 display 属性,我们也应该更改 thead 元素的属性,以防止破坏表格布局。
例子:
Display table with vertical scrollbar
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Content
Content
Content
Content
Content
Content
Content
Content
Content
Content
Content
Content
Content
Content
Content
输出: