使HTML表单元格中的文本与其他单元格重叠

use*_*797 3 html css

我想在一个单元格中有一些较长的文本,以便在下一个单元格中重叠而不是换行,但又不要使第一列变大。

在此处输入图片说明

如果我给牢房

white-space: nowrap;
position: absolute;
Run Code Online (Sandbox Code Playgroud)

它将处于正确的位置,但其他文本将在其下方流动。

感谢您的快速解答。

Juk*_*ela 6

您可以通过设置overflow: visible,防止换行和设置固定的宽度(也需要固定的表格布局),使一个单元格的内容流到同一行的其他单元格中。您还需要一段时间为表格设置固定宽度,因为否则浏览器将无法固定表格布局。

<style>
.x { 
  width: 3em;
  white-space: nowrap;
  overflow: visible;
  color: red;
}
table {
  table-layout: fixed;
}
th:nth-child(1) { width: 3em; }
th:nth-child(2) { width: 15em; }
th:nth-child(3) { width: 2em; }
th:nth-child(4) { width: 7em; }
th:nth-child(5) { width: 3em; }
</style>
<table border cellspacing=0>
<thead>
   <th>nr<th>name<th>year<th>category<th>price
<tbody>
<tr>
  <td><div class=x>A longer line that should not wrap , but go over the other cells</div></td>
  <td><td><td><td>
<tr>
  <td>999.0
  <td>Some name
  <td>2000
  <td>Some category
  <td>135.32
</table>
Run Code Online (Sandbox Code Playgroud)

这是如此复杂,以至于您可能应该执行@MikeW建议的操作,这不会使单元格内容溢出到其他单元格,而是使该单元格跨所有五列。