CSS,bootstrap表格控制当td内容过长时用省略号表示,以及在不使用bootstrap时过长也用省略号表示
2015-12-04 14:38
731 查看
标签:
首先需要在table中设置table-layout:fixed;
然后在表头th中设置每列的宽度
然后在需要当长度大于一定数值时用省略号表示的td上面添加样式
bootstrap在设置表格大小时需要设置到th中,否则可能不会生效,以上在bootstrap中可用
当不使用bootstrap的时候可以使用如下样式,网上搜索到的,比较好用
首先需要在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: 98% 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>
相关文章推荐
- app bootstrap font icon
- bootstrap modal动态加载内容
- Bootstrap中的下拉菜单
- 全面解析Bootstrap手风琴效果
- bootstrap-datepicker 日期拾取器
- 全面解析Bootstrap手风琴效果
- bootstrap模态框
- 基于Bootstrap jQuery.validate Form表单验证实践
- Bootstrap历练实例:响应式导航(带有表单)
- Bootstrap简介及Bootstrap里的栅格系统col-md/sm/xs-x;
- [ruby]Rails中使用bootstrap
- HTML、CSS、Javascript、Bootstrap学习链接
- 10003---BootStrap网格系统
- bootstrap提供了六种列表效果
- 10002---BootStrap--CSS概览
- JS组件系列——两种bootstrap multiselect组件大比拼
- php bootstrap 实现简单登录
- bootstrap图片轮播
- 图片轮播(bootstrap)与 圆角搜索框(纯css)
- bootstrap基础