要设置表格自动换行,可以使用 CSS 的 'word-wrap' 属性或 'white-space' 属性。以下是示例代码:

<!DOCTYPE html>
<html>
<head>
<style>
table {
  width: 100%;
  border-collapse: collapse;
}

td {
  border: 1px solid black;
  padding: 8px;
  word-wrap: break-word; /* 使用word-wrap属性自动换行 */
}

/* 或者使用white-space属性自动换行 */
/* td {
  border: 1px solid black;
  padding: 8px;
  white-space: pre-wrap;
} */
</style>
</head>
<body>

<table>
  <tr>
    <td>This is a very long text that will wrap automatically in the table cell.</td>
    <td>Another long text that will wrap automatically in the table cell.</td>
  </tr>
</table>

</body>
</html>

在上面的示例中,'word-wrap: break-word;' 属性会使单元格中的文本自动换行。如果你更喜欢使用 'white-space: pre-wrap;' 属性,你可以将注释部分的代码取消注释,并注释掉前面的代码。

HTML 表格自动换行设置

原文地址: https://www.cveoy.top/t/topic/pk81 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录