word-break在chrome中显示超出列宽

本文介绍了一种解决表格列内容过多导致布局错乱的方法,通过使用CSS的word-break属性和定义宽度,使得超出宽度的内容能够自动换行,从而保持表格整体布局的美观。
<div style="width:600px;text-align:left;word-break:break-all;"></div>

我把他们添加到一个table中的一列,

刚开始没有添加word-break:

出现了chrome浏览器中,因为这一列内容很多,导致挤得其他列都很窄很窄、

所以就用了上面的word-break属性,并且定义了宽度,这样,如果内容超出了宽度,这列内容就会换行了。

<table class="w-full border-collapse"> <!-- 表头 --> <thead> <tr class="bg-gray-100"> <th colspan="6" class="py-3 px-4 border border-gray-300 font-bold text-gray-800 text-center whitespace-nowrap" > 肉类 </th> <th colspan="6" class="py-3 px-4 border border-gray-300 font-bold text-gray-800 text-center whitespace-nowrap" > 海鲜类 </th> <th colspan="6" class="py-3 px-4 border border-gray-300 font-bold text-gray-800 text-center whitespace-nowrap" > 蔬菜类 </th> <th colspan="6" class="py-3 px-4 border border-gray-300 font-bold text-gray-800 text-center whitespace-nowrap" > 干货类 </th> </tr> <tr class="bg-gray-50 whitespace-nowrap"> <!-- 肉类子表头 --> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <!-- 海鲜类子表头 --> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <!-- 蔬菜类子表头 --> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <!-- 干货类子表头 --> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> </tr> </thead> <!-- 表格内容 --> <tbody> <tr v-for="(row, rowIndex) in displayedItems" :key="rowIndex" class="hover:bg-gray-50 transition-colors duration-150 whitespace-nowrap" > <!-- 肉类数据 --> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.meat1?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.meat1 ? getSupplierColorStyle(row.meat1.supplierId) : {} " > {{ row.meat1?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.meat1?.quantity || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.meat2?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.meat2 ? getSupplierColorStyle(row.meat2.supplierId) : {} " > {{ row.meat2?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.meat2?.quantity || "" }} </td> <!-- 海鲜类数据 --> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.seafood1?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.seafood1 ? getSupplierColorStyle(row.seafood1.supplierId) : {} " > {{ row.seafood1?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.seafood1?.quantity || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.seafood2?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.seafood2 ? getSupplierColorStyle(row.seafood2.supplierId) : {} " > {{ row.seafood2?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.seafood2?.quantity || "" }} </td> <!-- 蔬菜类数据 --> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.vegetable1?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.vegetable1 ? getSupplierColorStyle(row.vegetable1.supplierId) : {} " > {{ row.vegetable1?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.vegetable1?.quantity || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.vegetable2?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.vegetable2 ? getSupplierColorStyle(row.vegetable2.supplierId) : {} " > {{ row.vegetable2?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.vegetable2?.quantity || "" }} </td> <!-- 干货类数据 --> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.dry1?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style="row.dry1 ? getSupplierColorStyle(row.dry1.supplierId) : {}" > {{ row.dry1?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.dry1?.quantity || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.dry2?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style="row.dry2 ? getSupplierColorStyle(row.dry2.supplierId) : {}" > {{ row.dry2?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.dry2?.quantity || "" }} </td> </tr> <!-- 空状态 --> <tr v-if="displayedItems.length === 0"> <td colspan="24" class="py-8 text-center text-gray-500 border border-gray-300" > 暂无数据 </td> </tr> </tbody> </table>大小自适应
最新发布
10-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值