【发布时间】:2020-07-07 01:54:58
【问题描述】:
我目前有以下实现,我希望表格的主体可以滚动。但是,列宽都是相等的,我试图弄清楚如何根据内容实现灵活的表格单元格宽度,同时保持正文的滚动。想法?
.modal {
height: 300px;
}
.first {
height: 100%;
}
table.list {
border-collapse: collapse;
width: 100%;
height: 100%;
}
thead,
tbody tr {
display: table;
width: 100%;
table-layout: fixed;
}
thead {
font-weight: bold;
border-bottom: 1px solid #ccc;
height: 40px;
}
th {
padding: 0 $now-global-space--sm 0 $now-global-space--md;
text-align: left;
word-break: break-word;
hyphens: auto;
}
tbody {
overflow: auto;
display: block;
height: calc(100% - 40px);
}
tr {
line-height: 1.5;
border: none;
border-collapse: none;
min-height: 40px;
}
td {
min-height: 40px;
min-width: 40px;
padding: 4px;
text-align: left;
word-break: break-word;
hyphens: auto;
}
tr:nth-child(2n) td {
background-color: red;
}
tr:hover td {
background-color: pink;
}
<div class="modal">
<div class="first">
<table class="list" role="grid">
<thead>
<tr role="row">
<th role="columnheader">Date</th>
<th role="columnheader">Action</th>
<th role="columnheader">Comment</th>
</tr>
</thead>
<tbody>
<tr role="row">
<td role="gridcell">Mar 24</td>
<td role="gridcell">somoene</td>
<td role="gridcell">ddddd</td>
</tr>
<tr role="row">
<td role="gridcell">Mar 23</td>
<td role="gridcell">someone</td>
<td role="gridcell">ddddd</td>
</tr>
<tr role="row">
<td role="gridcell">Mar 22</td>
<td role="gridcell">someone</td>
<td role="gridcell">dd</td>
</tr>
<tr role="row">
<td role="gridcell">Mar 21</td>
<td role="gridcell">someone</td>
<td role="gridcell">asd</td>
</tr>
<tr role="row">
<td role="gridcell">Mar 20</td>
<td role="gridcell">someone</td>
<td role="gridcell">asdasdsadasdsa</td>
</tr>
<tr role="row">
<td role="gridcell">Mar 14</td>
<td role="gridcell">someone</td>
<td role="gridcell">asdasdsadsadsadsa</td>
</tr>
<tr role="row">
<td role="gridcell">Mar 7</td>
<td role="gridcell">lala</td>
<td role="gridcell">asdasdsadsa</td>
</tr>
</tbody>
</table>
</div>
</div>
【问题讨论】:
-
如果您希望评论栏中的内容最多,您可以分配一个可以为其指定宽度的类
标签: css