如果可能的话,我想用自动换行来制作表格。我正在使用white-space: pre-line;
css 类属性。但随后单元格高度将发生变化。看图片。如何将行高固定为 28px?当单元格没有足够空间时,如何禁止自动换行?
table {
border-collapse: collapse;
border-spacing: 0;
table-layout: fixed;
width: 1px;
background-color: #ddd;
font-size: 14px;
}
tr {
vertical-align: top;
}
td {
box-sizing: border-box;
position: relative;
border-width: 0 0 1px 1px;
padding-left: 12px;
padding-right: 12px;
padding-top: 4px;
border-style: solid;
border-color: #ffffff;
height: 28px;
}
td div {
overflow: hidden;
white-space: pre-line;
/* white-space: nowrap; */
text-overflow: ellipsis;
}
<div style="width: 385px; height: 280px;">
<table>
<col width="40" />
<col width="112" />
<col width="74" />
<col width="159" />
<tr>
<td colspan="1" rowspan="2" height="56">
<div><...></div>
</td>
<td class="bg-viewers-cube-pivot-total" colspan="1" rowspan="2" height="56">
<div>Total:</div>
</td>
<td class="bg-viewers-cube-pivot-total" colspan="1" rowspan="1" height="28">
<div>WordOne + WordTwo</div>
</td>
<td class="bg-viewers-cube-pivot-total" colspan="1" rowspan="1" height="28">
<div>Sum</div>
</td>
</tr>
<tr>
<td class="bg-viewers-cube-pivot-total" colspan="1" rowspan="1" height="28">
<div>Logical</div>
</td>
<td class="bg-viewers-cube-pivot-total" colspan="1" rowspan="1" height="28">
<div>Count</div>
</td>
</tr>
<tr>
<td colspan="1" rowspan="25" height="700">
<div>
</div>
</td>
<td colspan="1" rowspan="2" height="56">
<div><...></div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>WordOne + WordTwo</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>Sum</div>
</td>
</tr>
<tr>
<td colspan="1" rowspan="1" height="28">
<div>Logical</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>Count</div>
</td>
</tr>
<tr>
<td colspan="1" rowspan="2" height="56">
<div>01.01.2000</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>WordOne + WordTwo</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>Sum</div>
</td>
</tr>
<tr>
<td colspan="1" rowspan="1" height="28">
<div>Logical</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>Count</div>
</td>
</tr>
<tr>
<td colspan="1" rowspan="2" height="56">
<div>01.01.2000 0:10:00</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>WordOne + WordTwo</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>Sum</div>
</td>
</tr>
<tr>
<td colspan="1" rowspan="1" height="28">
<div>Logical</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>Count</div>
</td>
</tr>
<tr>
<td colspan="1" rowspan="2" height="56">
<div>01.01.2000 0:20:00</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>WordOne + WordTwo</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>Sum</div>
</td>
</tr>
<tr>
<td colspan="1" rowspan="1" height="28">
<div>Logical</div>
</td>
<td colspan="1" rowspan="1" height="28">
<div>Count</div>
</td>
</tr>
</table>
</div>