【发布时间】:2014-12-17 22:55:08
【问题描述】:
我已成功使用overflow: ellipsis 获得两个跨度以在表格单元格内工作,同时保持响应。
手头的问题是我需要使用 3 部分图像将两个跨度之一标记为选中。
在最简单的形式中,我有一个具有以下结构的表:
<table class="my-table table table-bordered table-striped">
<tbody>
<tr>
<td class="truncate-container">
<span class="truncate selected">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>
<span class="truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit</span>
</td>
</tr>
</tbody>
</table>
CSS:
.my-table {
width: 100%;
}
.truncate-container {
border: none !important;
max-width: 200px;
white-space: nowrap;
}
.truncate-container .truncate {
width: 48%;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
}
.selected {
position: relative;
height: 28px;
margin: 0 15px;
background: url("http://i.stack.imgur.com/DaQcG.png");
display: inline-block;
color: blue;
}
.selected::before,
.selected::after {
content: ' ';
position: absolute;
top: 0;
width: 15px;
height: 28px;
}
.selected::before {
left: -14px;
background: url("http://i.stack.imgur.com/6m2HC.png") no-repeat;
}
.selected::after {
right: -8px;
background:url("http://i.stack.imgur.com/2WA5B.png") 100% no-repeat;
}
如果您调整 HTML 窗格的大小,您可以看到省略号正常工作,但选择没有按预期工作。
伪元素 ::before 和 ::after 与省略号的这种特殊组合可以在纯 CSS 中完成,还是我必须求助于 JS(Angular 过滤器)进行截断?
【问题讨论】:
-
显然不喜欢将
overflow:hidden属性应用于.truncate-container .truncate选择器和使用伪元素的组合。我的猜测是,由于:before和:after不是它们自己的元素,因此元素占据了整个分配的宽度,因此伪元素不可见。
标签: css pseudo-element ellipsis