Html 如何使用溢出滚动设置 tbody 高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23989463/
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 to set tbody height with overflow scroll
提问by Maverick
I am facing problem while setting tbody height width overflow scroll.
我在设置 tbody 高度宽度溢出滚动时遇到问题。
<style>
tbody{
height:50px;display:block;overflow:scroll
}
</style>
<h3>Table B</h3>
<table style="border: 1px solid red;width:300px;display:block">
<thead>
<tr>
<td>Name</td>
<td>phone</td>
</tr>
</thead>
<tbody style='height:50px;display:block;overflow:scroll'>
<tr>
<td>AAAA</td>
<td>323232</td>
</tr>
<tr>
<td>BBBBB</td>
<td>323232</td>
</tr>
<tr>
<td>CCCCC</td>
<td>3435656</td>
</tr>
</tbody>
</table>
I want table B like Table A with overflow scroll.
我想要像表 A 一样带有溢出滚动的表 B。
Any help will be appreciated.
任何帮助将不胜感激。
Many Thanks, M.
非常感谢,M。
回答by G-Cyrillus
if you want tbody
to show a scroll , turn it into a block
.
如果你想tbody
显示一个滚动,把它变成一个block
.
To keep behavior of table
, turn tr
into table
.
为保持行为table
,tr
变为table
。
to spray evenly the cells , use table-layout:fixed;
均匀喷洒细胞,使用 table-layout:fixed;
CSS for your HTML test :
用于 HTML 测试的 CSS:
table ,tr td{
border:1px solid red
}
tbody {
display:block;
height:50px;
overflow:auto;
}
thead, tbody tr {
display:table;
width:100%;
table-layout:fixed;/* even columns width , fix width of table too*/
}
thead {
width: calc( 100% - 1em )/* scrollbar is average 1em/16px width, remove it from thead width */
}
table {
width:400px;
}
If tbody
doesn't show a scroll, because content is less than height
or max-height
, set the scroll anytime with : overflow-y:scroll;
. DEMO 2
如果tbody
不显示滚动,因为内容小于height
或max-height
,请随时使用 : 设置滚动overflow-y:scroll;
。演示 2
回答by Dinesh Vaitage
It is simple way to use scroll bar to table body
这是使用滚动条到表格正文的简单方法
/* It is simple way to use scroll bar to table body*/
.tableBodyScroll tbody {
display: block;
max-height: 300px;
overflow-y: scroll;
}
.tableBodyScroll thead,
tbody tr {
display: table;
width: 100%;
table-layout: fixed;
}
<table class="tableBodyScroll">
<thead>
<th>Invoice Number</th>
<th>Purchaser</th>
<th>Invoice Amount</th>
<th>Invoice Date</th>
</thead>
<tbody>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
<tr>
<td>INV-1233</td>
<td>Dinesh Vaitage</td>
<td>0</td>
<td>01/12/2017</td>
</tr>
</tbody>
</table>
回答by brandonkal
Another approach is to wrap your table in a scrollable element and set the header cells to stick to the top.
另一种方法是将表格包装在可滚动元素中,并将标题单元格设置为贴在顶部。
The advantage of this approach is that you don't have to change the display on tbody and you can leave it to the browser to calculate column width while keeping the header cell widths in line with the data cell column widths.
这种方法的优点是您不必更改 tbody 上的显示,您可以将它留给浏览器来计算列宽,同时保持标题单元格宽度与数据单元格列宽保持一致。
/* Set a fixed scrollable wrapper */
.tableWrap {
height: 200px;
border: 2px solid black;
overflow: auto;
}
/* Set header to stick to the top of the container. */
thead tr th {
position: sticky;
top: 0;
}
/* If we use border,
we must use table-collapse to avoid
a slight movement of the header row */
table {
border-collapse: collapse;
}
/* Because we must set sticky on th,
we have to apply background styles here
rather than on thead */
th {
padding: 16px;
padding-left: 15px;
border-left: 1px dotted rgba(200, 209, 224, 0.6);
border-bottom: 1px solid #e8e8e8;
background: #ffc491;
text-align: left;
/* With border-collapse, we must use box-shadow or psuedo elements
for the header borders */
box-shadow: 0px 0px 0 2px #e8e8e8;
}
/* Basic Demo styling */
table {
width: 100%;
font-family: sans-serif;
}
table td {
padding: 16px;
}
tbody tr {
border-bottom: 2px solid #e8e8e8;
}
thead {
font-weight: 500;
color: rgba(0, 0, 0, 0.85);
}
tbody tr:hover {
background: #e6f7ff;
}
<div class="tableWrap">
<table>
<thead>
<tr>
<th><span>Month</span></th>
<th>
<span>Event</span>
</th>
<th><span>Action</span></th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>February. An extra long string.</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>March</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>April</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>May</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>June</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>July</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>August</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>September</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>October</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>November</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
<tr>
<td>December</td>
<td>AAA</td>
<td><span>Invite | Delete</span></td>
</tr>
</tbody>
</table>
</div>
回答by Kheema Pandey
By default overflow
does not apply to table group elements unless you give a display:block
to <tbody>
also you have to give a position:relative
and display: block
to <thead>
. Check the DEMO.
默认情况下overflow
不适用于表格组元素,除非你给 a display:block
to<tbody>
也你必须给 a position:relative
and display: block
to <thead>
。检查演示。
.fixed {
width:350px;
table-layout: fixed;
border-collapse: collapse;
}
.fixed th {
text-decoration: underline;
}
.fixed th,
.fixed td {
padding: 5px;
text-align: left;
min-width: 200px;
}
.fixed thead {
background-color: red;
color: #fdfdfd;
}
.fixed thead tr {
display: block;
position: relative;
}
.fixed tbody {
display: block;
overflow: auto;
width: 100%;
height: 100px;
overflow-y: scroll;
overflow-x: hidden;
}
回答by Gil Baggio
Simplest of all solutions:
最简单的解决方案:
Add the below code in CSS:
在 CSS 中添加以下代码:
.tableClassName tbody {
display: block;
max-height: 200px;
overflow-y: scroll;
}
.tableClassName thead, .tableClassName tbody tr {
display: table;
width: 100%;
table-layout: fixed;
}
.tableClassName thead {
width: calc( 100% - 1.1em );
}
1.1 emis the average width of the scroll bar, please modify this if needed.
1.1 em是滚动条的平均宽度,如有需要请修改。
回答by Suresh Ponnukalai
Change your second table code like below.
更改您的第二个表代码,如下所示。
<table style="border: 1px solid red;width:300px;display:block;">
<thead>
<tr>
<td width=150>Name</td>
<td width=150>phone</td>
</tr>
</thead>
<tbody style='height:50px;overflow:auto;display:block;width:317px;'>
<tr>
<td width=150>AAAA</td>
<td width=150>323232</td>
</tr>
<tr>
<td>BBBBB</td>
<td>323232</td>
</tr>
<tr>
<td>CCCCC</td>
<td>3435656</td>
</tr>
</tbody>
</table>
回答by kazuar
In my case I wanted to have responsive table height instead of fixed height in pixels as the other answers are showing. To do that I used percentage of visible height property and overflow on div containing the table:
在我的情况下,我想要响应式表格高度,而不是像其他答案显示的那样以像素为单位固定高度。为此,我在包含表格的 div 上使用了可见高度属性的百分比和溢出:
&__table-container {
height: 70vh;
overflow: scroll;
}
This way the table will expand along with the window being resized.
这样,表格将随着窗口大小的调整而扩展。
回答by ErJab
Based on this answer, here's a minimal solution if you're already using Bootstrap:
根据这个答案,如果您已经在使用 Bootstrap,这里有一个最小的解决方案:
div.scrollable-table-wrapper {
height: 500px;
overflow: auto;
thead tr th {
position: sticky;
top: 0;
}
}
<div class="scrollable-table-wrapper">
<table class="table">
<thead>...</thead>
<tbody>...</tbody>
</table>
</div>
Tested on Bootstrap v3
在 Bootstrap v3 上测试
回答by J?rgen Rudolph L?ker
Making scrolling tables is always a challenge. This is a solution where the table is scrolled both horizontally and vertically with fixed height on tbody making theader and tbody "stick" (without display: sticky). I've added a "big" table just to show. I got inspiration from G-Cyrillus to make the tbody display:block; But when it comes to width of a cell (both in header and body), it's depending on the inside content. Therefore I added content with specific width inside each cell, both in thead and minimum first row in tbody (the other rows adapt accordingly)
制作滚动表始终是一个挑战。这是一个解决方案,其中表格在 tbody 上以固定高度水平和垂直滚动,使 theader 和 tbody“粘住”(不显示:粘滞)。我添加了一个“大”表只是为了显示。我从 G-Cyrillus 那里得到灵感来制作 tbody display:block; 但是当涉及到单元格的宽度(在标题和正文中)时,它取决于内部内容。因此,我在每个单元格内添加了具有特定宽度的内容,包括 tbody 中的 thead 和最小第一行(其他行相应地进行调整)
.go-wrapper {
overflow-x: auto;
width: 100%;
}
.go-wrapper table {
width: auto;
}
.go-wrapper table tbody {
display: block;
height: 220px;
overflow: auto;
}
.go-wrapper table thead {
display: table;
}
.go-wrapper table tfoot {
display: table;
}
.go-wrapper table thead tr,
.go-wrapper table tbody tr,
.go-wrapper table tfoot tr {
display: table-row;
}
.go-wrapper table th,
.go-wrapper table td {
white-space: nowrap;
}
.go-wrapper .aw-50 { min-height: 1px; width: 50px; }
.go-wrapper .aw-100 { min-height: 1px; width: 100px; }
.go-wrapper .aw-200 { min-height: 1px; width: 200px; }
.go-wrapper .aw-400 { min-height: 1px; width: 400px; }
/***** Colors *****/
.go-wrapper table {
border: 2px solid red
}
.go-wrapper table thead,
.go-wrapper table tbody,
.go-wrapper table tfoot {
outline: 1px solid green
}
.go-wrapper td {
outline: 1px solid blue
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Template</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<div class="container">
<div class="row mt-5 justify-content-md-center">
<div class="col-8">
<div class="go-wrapper">
<table class="table">
<thead>
<tr>
<th><div class="aw-50" ><div class="checker"><span><input type="checkbox" class="styled"></span></div></div></th>
<th><div class="aw-200">Name</div></th>
<th><div class="aw-50" >Week</div></th>
<th><div class="aw-100">Date</div></th>
<th><div class="aw-100">Time</div></th>
<th><div class="aw-200">Project</div></th>
<th><div class="aw-400">Text</div></th>
<th><div class="aw-200">Activity</div></th>
<th><div class="aw-50" >Hours</th>
<th><div class="aw-50" >Pause</div></th>
<th><div class="aw-100">Status</div></th>
</tr>
</thead>
<tbody>
<tr>
<td><div class="aw-50"><div class="checker"><span><input type="checkbox" class="styled"></span></div></div></td>
<td><div class="aw-200">AAAAA</div></td>
<td><div class="aw-50" >15</div></td>
<td><div class="aw-100">07.04.2020</div></td>
<td><div class="aw-100">10:00</div></td>
<td><div class="aw-200">Project 1</div></td>
<td><div class="aw-400">Blah blah blah</div></td>
<td><div class="aw-200">Activity</div></td>
<td><div class="aw-50" >2t</div></td>
<td><div class="aw-50" >30min</div></td>
<td><div class="aw-100">Waiting</div></td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>BBBBB</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>CCCCC</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah Blah blah blah</td>
<td>Activity Activity Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>DDDDD</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>EEEEE</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>FFFFF</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity Activity Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>GGGGG</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>HHHHH</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>IIIII</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>JJJJJ</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>KKKKK</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>LLLLL</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>MMMMM</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>NNNNN</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>OOOOO</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>PPPPP</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>QQQQQ</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>RRRRR</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>SSSSS</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>TTTTT</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>UUUUU</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>VVVVV</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>XXXXX</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>YYYYY</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>ZZZZZ</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>?????</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>?????</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
<tr>
<td><div class="checker"><span><input type="checkbox" class="styled"></span></div></td>
<td>?????</td>
<td>15</td>
<td>07.04.2020</td>
<td>10:00</td>
<td>Project 1</td>
<td>Blah blah blah</td>
<td>Activity</td>
<td>2t</td>
<td>30min</td>
<td>Waiting</td>
</tr>
</tbody>
<tfoot>
<tr>
<th><div class="aw-50" ><div class="checker"><span><input type="checkbox" class="styled"></span></div></div></th>
<th><div class="aw-200">Name</div></th>
<th><div class="aw-50" >Week</div></th>
<th><div class="aw-100">Date</div></th>
<th><div class="aw-100">Time</div></th>
<th><div class="aw-200">Project</div></th>
<th><div class="aw-400">Text</div></th>
<th><div class="aw-200">Activity</div></th>
<th><div class="aw-50" >Hours</th>
<th><div class="aw-50" >Pause</div></th>
<th><div class="aw-100">Status</div></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
回答by bermz kastral
HTML:
HTML:
<table id="uniquetable">
<thead>
<tr>
<th> {{ field[0].key }} </th>
<th> {{ field[1].key }} </th>
<th> {{ field[2].key }} </th>
<th> {{ field[3].key }} </th>
</tr>
</thead>
<tbody>
<tr v-for="obj in objects" v-bind:key="obj.id">
<td> {{ obj.id }} </td>
<td> {{ obj.name }} </td>
<td> {{ obj.age }} </td>
<td> {{ obj.gender }} </td>
</tr>
</tbody>
</table>
CSS:
CSS:
#uniquetable thead{
display:block;
width: 100%;
}
#uniquetable tbody{
display:block;
width: 100%;
height: 100px;
overflow-y:overlay;
overflow-x:hidden;
}
#uniquetable tbody tr,#uniquetable thead tr{
width: 100%;
display:table;
}
#uniquetable tbody tr td, #uniquetable thead tr th{
display:table-cell;
width:20% !important;
overflow:hidden;
}
this will work as well:
这也将起作用:
#uniquetable tbody {
width:inherit !important;
display:block;
max-height: 400px;
overflow-y:overlay;
}
#uniquetable thead {
width:inherit !important;
display:block;
}
#uniquetable tbody tr, #uniquetable thead tr {
display:inline-flex;
width:100%;
}
#uniquetable tbody tr td, #uniquetable thead tr th {
display:block;
width:20%;
border-top:none;
text-overflow: ellipsis;
overflow: hidden;
max-height:400px;
}