利用CSS让<td>截断超长的内容

本文介绍了如何使用table-layout属性来固定表格布局,并通过设置td元素的nowrap样式及overflow等属性实现内容溢出时的省略显示效果。此外,还介绍了title属性的作用,即当鼠标悬停在单元格上时显示完整内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要点:
1.<table style="table-layout:fixed">
2.<td nowrap style="overflow:hidden; text-overflow:ellipsis;word-break:keep-all;" title='框中内容'>

设置title是为了让鼠标停留在td框上时能够看到全部内容.
表格内容太多怎么隐藏悬停才展示完整内容<div style="max-height: 900px;overflow: auto;"> <table class="table table-hover table-bordered" style="margin-bottom: 0;"> <thead class="bg-light" style="position: sticky; top: 0; z-index: 1;"> <tr class="head-table"> <th>序号</th> <th>异常标识码</th> <th>操作</th> <th>异常类型</th> <th>工段</th> <th>异常来源</th> <th>异常项目</th> <th>异常等级</th> <th>设备</th> <th>批次号</th> <th>站点</th> <th>工艺流程</th> <th>产品料号</th> <th>异常描述</th> <th>异常CODE类型</th> <th>异常数据</th> <th>异常开始时间</th> <th>是否处理</th> <th>处理人员</th> <th>处理备注</th> <th>结案时间</th> </tr> </thead> <tbody> <tr th:each="data,iterStat : ${page.records}" class="center-table"> <td th:text="${iterStat.count}"></td> <td th:text="${data.ALARMTIMEKEY}"></td> <td th:text="${iterStat.count}"></td> <td th:text="${data.ISSUETYPE}"></td> <td th:text="${data.FACTORYNAME}"></td> <td th:text="${data.ALARMTYPE}"></td> <td th:text="${data.ALARMID}"></td> <td th:text="${data.ALARMLEVEL}"></td> <td th:text="${data.MACHINENAME}"></td> <td th:text="${data.LOTNAME}"></td> <td th:text="${data.PROCESSOPERATIONNAME}"></td> <td th:text="${data.PROCESSFLOWNAME}"></td> <td th:text="${data.PRODUCTSPECNAME}"></td> <td th:text="${data.ALARMCOMMENT}"></td> <td th:text="${data.REASONCODETYPE}"></td> <td th:text="${data.REASONCODE}"></td> <td th:text="${data.START_TIME}"></td> <td th:text="${data.SOLVEFLAG}"></td> <td th:text="${data.SOLVE_USER}"></td> <td th:text="${data.SOLVE_REASON}"></td> <td th:text="${data.END_TIME}"></td> </tr> <!-- 空数据提示 --> <tr th:if="${page.records.isEmpty()}"> <td colspan="21" class="text-center text-muted">暂无数据</td> </tr> </tbody> </table> </div>
03-08
<p-table [value]="salesOrderList" stripedRows class="w-full" dataKey="vehicleSeq" [expandedRowKeys]="expandedRows"> <ng-template #header> <tr> <th>工厂</th> <th class="fontLine" style="min-width: 100px">装货日期</th> <th class="fontLine" style="min-width: 100px">发货日期</th> <th class="fontLine" style="min-width: 100px">车牌号</th> <th class="fontLine" style="min-width: 100px">车次</th> <th class="fontLine" style="min-width: 100px">优先级</th> <th class="fontLine" style="min-width: 100px">拼车</th> <th class="fontLine" style="min-width: 100px">计划到库</th> <th class="fontLine" style="min-width: 100px">到库时间</th> <th class="fontLine" style="min-width: 100px">状态</th> </tr> </ng-template> <ng-template #body let-product let-expanded="expanded"> <tr> <td> <div class="flex gap-2 items-center"> <button (click)="!expanded ? onClickSalesOrderDetail(product) : null" pButton class="text-sm" pRipple [pRowToggler]="product" [text]="true" [rounded]="true" [plain]="true" [icon]="expanded ? 'pi pi-chevron-down' : 'pi pi-chevron-right'" style="padding-right: 6px;"></button> <span>{{ product.factoryName }}</span> </div> </td> <td>{{ product.loadDate }}</td> <td>{{ product.deliveryDate }}</td> <td>{{ product.vehicleNo }}</td> <td>{{ product.vehicleSeq }}</td> <td> <p-select class="w-full" [(ngModel)]="product.priority" [options]="priorityList" optionLabel="dicName" optionValue="dicCode" [appendTo]="'body'"> </p-select> </td> <td>{{ product.isCarpool ? '是' : '否' }}</td> <td>{{ product.planArrivalTime }}</td> <td>{{ product.actualArrivalTime }}</td> <td> <div class="py-1 rounded text-center" [ngClass]="{'status-done': (product.status | salesOrderStatus) === '已装车','status-warning': (product.status | salesOrderStatus) === '待通知','status-error': (product.status | salesOrderStatus) === '待排序'}"> {{ product.status | salesOrderStatus }}</div> </td> </tr> </ng-template> <ng-template #expandedrow let-product> <tr> <td colspan="100%" class="bg-white !pl-8 !pr-0"> <div class="pl-6" style="border-left: 1px #c30001 solid"> <p-table [value]="salesOrderDetail" class="wareList"> <ng-template #header> <tr> <th>发货仓库</th> <th class="fontLine">备货单</th> <th class="fontLine">合同</th> <th class="fontLine">到货日期</th> <th class="fontLine">商业公司</th> <th class="fontLine">装载顺序</th> <th class="fontLine">批次</th> <th class="fontLine">物料编号</th> <th class="fontLine">物料描述</th> <th class="fontLine">数量</th> </tr> </ng-template> <ng-template #body let-order> <tr> <td>{{ order.deliveryWarehouse }}</td> <td>{{ order.packingList }}</td> <td>{{ order.contractNo }}</td> <td>{{ order.arrivalDate }}</td> <td>{{ order.businessCompany }}</td> <td>{{ order.loadingOrder }}</td> <td>{{ order.batchNo }}</td> <td>{{ order.materialCode }}</td> <td>{{ order.materialDesc }}</td> <td>{{ order.quantity }}</td> </tr> </ng-template> </p-table> 我的html是这样的结构
最新发布
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值