要控制HTML表格中每一列的内容过长时自动换行,可以使用CSS的'word-wrap'属性和'table-layout'属性。
首先,为包含表格的'
'元素添加CSS样式'table-layout: fixed;',这将使表格的每一列宽度固定。
然后,为表格中的每个单元格添加CSS样式'word-wrap: break-word;',这将使单元格内容在需要时自动换行。
以下是一个示例:
<style>
table {
table-layout: fixed;
width: 100%;
}
td {
word-wrap: break-word;
}
</style>
<table>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td>Maecenas ac tincidunt elit, sed tincidunt leo.</td>
<td>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</td>
</tr>
</table>
在上面的示例中,表格的每一列都会自动换行,以适应内容的长度。
原文地址: https://www.cveoy.top/t/topic/rv7 著作权归作者所有。请勿转载和采集!
免费AI点我,无需注册和登录