【发布时间】:2014-06-19 08:44:15
【问题描述】:
我正在使用 bootstrap 3 表,当我将大文本放入表中时,它会被包裹在几行中,但我希望它以响应方式在末尾用三个点截断,而不会弄乱布局表(我找到了一些解决方案,但效果不佳)。
这可能吗?怎么样?
PS:欢迎任何解决方案,但如果可能的话,我希望它只是 HTML/CSS。
【问题讨论】:
标签: html css twitter-bootstrap-3 responsive-design
我正在使用 bootstrap 3 表,当我将大文本放入表中时,它会被包裹在几行中,但我希望它以响应方式在末尾用三个点截断,而不会弄乱布局表(我找到了一些解决方案,但效果不佳)。
这可能吗?怎么样?
PS:欢迎任何解决方案,但如果可能的话,我希望它只是 HTML/CSS。
【问题讨论】:
标签: html css twitter-bootstrap-3 responsive-design
您需要使用 table-layout:fixed 才能使 CSS 省略号作用于表格单元格。
.table {
table-layout:fixed;
}
.table td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
【讨论】:
我是这样做的(你需要添加一个类 text 到 <td> 并将文本放在 <span> 之间:
HTML
<td class="text"><span>looooooong teeeeeeeeext</span></td>
SASS
.table td.text {
max-width: 177px;
span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
max-width: 100%;
}
}
CSS等效
.table td.text {
max-width: 177px;
}
.table td.text span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
max-width: 100%;
}
并且它仍然是移动响应的(忘记它,layout=fixed)并且会保持原来的行为。
PS:当然 177px 是自定义尺寸(随便放什么)。
【讨论】:
display: block 以删除这添加到表格行底部的一小部分空白。见stackoverflow.com/questions/45588761/…
这是我实现的,但必须设置宽度,并且不能是百分比。
.trunc{
width:250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
table tr td {
padding: 5px
}
table tr td {
background: salmon
}
table tr td:first-child {
background: lightsalmon
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<table>
<tr>
<td>Quisque dignissim ante in tincidunt gravida. Maecenas lectus turpis</td>
<td>
<div class="trunc">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</td>
</tr>
</table>
或者这个:http://collaboradev.com/2015/03/28/responsive-css-truncate-and-ellipsis/
【讨论】:
我正在使用引导程序。
我使用了 css 参数。
.table {
table-layout:fixed;
}
.table td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
和引导网格系统参数,像这样。
<th class="col-sm-2">Name</th>
<td class="col-sm-2">hoge</td>
【讨论】: