限制TD文本长度

时间:2015-06-26 10:37:58

标签: css backgrid

我有一个由backgrid生成的网格。

我想限制文本长度,每个td必须在一行上。

td上的width属性无效。

感谢您的帮助。

enter image description here

2 个答案:

答案 0 :(得分:3)

根据您定义'限制'的方式,您可以简单地阻止包装和控制溢出:

td{
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

这会将内容保留为一行,如果文本内容超出td

的允许宽度,则会在末尾附加省略号

答案 1 :(得分:1)

你需要把'td'标签的文本放在'p'标签中,并给td标签一个像<td class="content_td"><p>Your text</p></td>这样的类 然后你可以像

一样用CSS编写
.content_td p {
    max-width: 100%;
    max-height: 100px;
    overflow-y: scroll;
    text-overflow: ellipsis;
}