我想使用 CSStext-overflow
在表格单元格中,如果文本太长而无法容纳在一行中,它将用省略号进行剪辑,而不是换行到多行。这可能吗?
我试过这个:
td {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
But the white-space: nowrap
似乎使文本(及其单元格)不断向右扩展,将表格的总宽度推到其容器的宽度之外。但是,如果没有它,文本在到达单元格边缘时会继续换行。
要在文本溢出表格单元格时剪切带有省略号的文本,您需要设置max-width
每个的 CSS 属性td
溢出工作的类。没有额外的布局div
需要元素:
td
{
max-width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
对于响应式布局;使用max-width
CSS 属性指定列的有效最小宽度,或者只使用max-width: 0;
无限的灵活性。此外,包含的表格需要特定的宽度,通常width: 100%;
,并且列的宽度通常设置为总宽度的百分比
table {width: 100%;}
td
{
max-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
td.column_a {width: 30%;}
td.column_b {width: 70%;}
历史:对于 IE 9(或更低版本),您需要在 HTML 中包含此内容,以修复特定于 IE 的渲染问题
<!--[if IE]>
<style>
table {table-layout: fixed; width: 100px;}
</style>
<![endif]-->
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)