目前
我有一个100%宽度的表,其中包含3列,其中有一个textarea,用户可以在其中输入文本。
我的目标是具有以下列宽行为:
奖励目标:如果屏幕宽度足够小,1个或多个列无法完全显示,请添加水平滚动。
码:
table {
border-collapse: collapse;
width: 100%;
border: 1px solid black;
table-layout: fixed;
}
th, td {
text-align: center;
border: 1px solid black;
padding: 10px;
}
.container {
border: 1px solid blue;
}
.text-area {
width: 100%;
box-sizing: border-box;
display: flex;
}
.fixed-min {
min-width: 600px;
}
<!DOCTYPE html>
<html>
<body>
<table>
<tbody>
<tr>
<th>Column 1 - has min width</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td>
<div class="container fixed-min">
<textarea class="text-area">Respect the minimum column width for this column.
</textarea>
</div>
</td>
<td>
<div class="container">
<textarea class="text-area">This column width should revert to default for the table.
</textarea>
</div>
</td>
<td>
<div class="container">
<textarea class="text-area">This column width should also revert to the default for the table.
</textarea>
</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
https://jsfiddle.net/bjLxuvfz/1/
问题
第1列的最小宽度为600px,但(1)类“容器”和(2)宽度不调整。
预期行为:
注意:
我已经根据要求进行了更改,为了实现这个删除table-layout:fixed
并添加外部div
到table
,使其在响应/移动模式下工作。请检查希望这将解决您的问题。我也建议按照标准在thead中制作。
table {
border-collapse: collapse;
width: 100%;
border: 1px solid black;
}
th, td {
text-align: center;
border: 1px solid black;
padding: 10px;
}
.container {
border: 1px solid blue;
}
.text-area {
width: 100%;
box-sizing: border-box;
display: flex;
}
.fixed-min {
min-width: 600px;
}
.res-table{
max-width:100%;
width: 100%;
overflow-x: auto;
}
<!DOCTYPE html>
<html>
<body>
<div class="res-table">
<table>
<tbody>
<tr>
<th width="600px">Column 1 - has min width</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td>
<div class="container fixed-min">
<textarea class="text-area">Respect the minimum column width for this column.
</textarea>
</div>
</td>
<td>
<div class="container">
<textarea class="text-area">This column width should revert to default for the table.
</textarea>
</div>
</td>
<td>
<div class="container">
<textarea class="text-area">This column width should also revert to the default for the table.
</textarea>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>