CSS,bootstrap表格控制当td内容过长时用省略号表示,以及在不使用bootstrap时过长也用省略号表示
2024-10-15 23:16:31
首先需要在table中设置table-layout:fixed;
<table style="table-layout:fixed"></table>
然后在表头th中设置每列的宽度
<table style="table-layout:fixed"> <th width="10%">Title01</th> <th width="20%">Title02</th> <!-- 其他th --> </table>
然后在需要当长度大于一定数值时用省略号表示的td上面添加样式
<table style="table-layout:fixed"> <th width="10%">Title01</th> <th width="20%">Title02</th> <!-- 其他th --> <c:foreach items = "" var ="" varStatus = ""> <td><title01</td> <td style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;"><title02</td> <!-- other td --> </c:foreach> </table>
bootstrap在设置表格大小时需要设置到th中,否则可能不会生效,以上在bootstrap中可用
当不使用bootstrap的时候可以使用如下样式,网上搜索到的,比较好用
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <style type="text/css"> .mytable { table-layout: fixed; width: % border:0px; margin: 0px; } .mytable tr td { text-overflow: ellipsis; /* for IE */ -moz-text-overflow: ellipsis; /* for Firefox,mozilla */ overflow: hidden; white-space: nowrap; border: 1px solid; text-align: left } </style> </head> <body> <table width="500px" class="mytable"> <tr> <td width="20%">再别康桥</td> <td width="80%"> 轻轻我走了,正如我轻轻地来,我挥一挥衣袖,不带走一片云彩 </td> </tr> </table> </body> </html>
最新文章
- CentOS下yum安装LAMP
- JAVA 8 方法引用 - Method References
- 深入理解计算机系统(2.7)---二进制浮点数,IEEE标准(重要)
- Unity3D中Console控制台的扩展
- DOTween文档
- Java正确转换html编码
- 【技术贴】解决bug mantisbt APPLICATION ERROR #1502 没有找到类别
- Percona-Galera-Monitoring-Template监控模板说明
- 【每天一个Linux命令】10. 用户账号的新建/修改/删除以及密码修改 useradd/usemod/userdel/passwd
- 关于hover没有效果的问题
- jBPM5 vs Actitivi
- android 中Log - 简单使用
- Java中的static关键字
- 虎说:bootstrap源码解读(重置模块)
- mysql 时间戳格式化函数FROM_UNIXTIME和UNIX_TIMESTAMP函数的使用说明
- Shell读取配置文件的方法
- sleep、wait、notify、notifyAll的区别
- VM12中CentOS7以NAT方式连接网络的方法
- maven 将jar包推送到自己本机的maven库
- js的快速搜索